Table of Contents

Name

future_fork - spawn a qthread as a future

Synopsis

#include <qthread/futurelib.h>

void
future_fork (const qthread_f *f, const void *arg, aligned_t *ret);

Description

This is a blocking function that will create a qthread on some location when the number of currently active threads on that location is below a certain threshold. If the number of currently active threads is too high, the function will block until some threads complete.

The first argument is a pointer to the qthread creating the future computation. This may be a NULL pointer if futures are created by a non-qthread. The second argument, f, is a function that will be run to completion by the created qthread. The last argument, arg, is an argument that will be passed to the specified function.

The qthread_f function must have a prototype like this:

void function(void *arg);

Threads which are spawned with future_fork() must call future_exit() as the final action of the thread in order to free memory and yield up status as an active thread.

When a thread creates future computations, the action may block, waiting for the number of active threads to drop. Deadlock may result if many active threads try to create futures. Therefore, when a thread attempts to create futures, it must explicitly declare itself inactive using the future_yield() function, then reactivate itself using the future_acquire() function.

The typical sequence for creating futures is:

1) yield
2) loop creating futures
3) [optional: join with futures]
4) acquire

See Also

future_join_all(3) , future_init(3) , future_exit(3) , future_yield(3) , future_acquire(3)


Table of Contents