Table of Contents

Name

qt_loop - a simple implementation of a threaded loop

Synopsis

#include <qthread/qloop.h>

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

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

Description

These functions provide 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() supports a stride argument, while qt_loop() 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 qthread 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 qthreads. But, if start is 50, stop is 100, and stride is 2, there will be 25 qthreads.

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

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

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

See Also

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


Table of Contents