Table of Contents

Name

qt_loop_future - a simple implementation of a threaded loop of futures

Synopsis

#include <qthread/qloop.h>

void
qt_loop_future (const size_t start, const size_t stop, const qt_loop_f func, void *argptr);

void
qt_loop_step_future (const size_t start, const size_t stop, const size_t stride, const qt_loop_f func, void *argptr);

Description

This function provides a simple C implementation of a threaded loop. This is similar to mt_loop, but does not provide much of the convenience and isomorphism that a C++ implementation can provide. On the other hand, it is more portable, and more predictable. The difference is that qt_loop_step_future() supports a stride argument, while qt_loop_future() assumes a stride of one.

This function can be thought of as akin to the following code:

unsigned int i;
for (i = start; i < stop; i += stride) {

func(i, i+1, argptr);
}

A future is spawned for every iteration of the above loop. Thus, if start is 50, stop is 100, and stride is 1, there will be 50 futures. But, if start is 50, stop is 100, and stride is 2, there will be 25 futures.

The func argument must be a function pointer with a qthread_f prototype, such as:

aligned_t func (size_t start, size_t stop, void *arg);

The return value of this function is ignored. However, qt_loop_future() will not return until all of the futures it spawns have returned.

See Also

qt_loop(3) , qt_loop_balance(3) , qt_loop_balance_future(3) , qt_loopaccum_balance(3) , qt_loopaccum_balance_future(3)


Table of Contents