Table of Contents

Name

qthread_fork, qthread_fork_precond, qthread_fork_syncvar, qthread_fork_to, qthread_fork_to_precond, qthread_fork_syncvar_to - spawn a qthread

Synopsis

#include <qthread.h>

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

int
qthread_fork_precond (qthread_f f, const void *arg, aligned_t *ret, int npreconds, ...);

int
qthread_fork_syncvar (qthread_f f, const void *arg, syncvar_t *ret);

int
qthread_fork_to (qthread_f f, const void *arg, aligned_t *ret, qthread_shepherd_id_t shepherd);

int
qthread_fork_precond_to (qthread_f f, const void *arg, aligned_t *ret, qthread_shepherd_id_t shepherd, int npreconds, ...);

int
qthread_fork_syncvar_to (qthread_f f, const void *arg, syncvar_t *ret, qthread_shepherd_id_t shepherd);

Description

These are the functions for generating new qthreads.

The first argument to these functions, f, is a function that will be run to completion by the created qthread. The second argument to these functions, arg, is an argument that will be passed to the specified function. Finally, ret is a pointer to the location that the return value of f will be placed into.

The qthread_f function must have a prototype like this:

aligned_t function(void *arg);

The qthread_fork_to(), qthread_fork_precond_to(), and qthread_fork_syncvar_to() functions spawn the qthread to a specific shepherd.

The qthread_fork_precond() and qthread_fork_precond_to() functions accept a list of precondition variables. The qthread will be created only when all precondition variables are full. The npreconds argument specifies how many variables are given in the varargs list.

When a qthread is spawned, it is immediately scheduled to be run, and may be executed by its shepherd at any time.

The return value of the function f will be placed into the memory pointed to by ret, in accordance with the full-empty bits. When qthread_fork() or qthread_fork_to() is called, ret will be emptied (as if it had been passed to qthread_empty() or qthread_syncvar_empty()). When the function f returns, the returned value will be stored into ret and ret will be filled. The way to block until a function has finished is to use qthread_readFF() or qthread_syncvar_readFF() on the ret pointer.

Environment

The operation of these functions is modified by the following environment variables:
QTHREAD_STACK_SIZE
This variable adjusts the size of the stacks that will be created for each thread. Changes to this value during the course of the program run are ignored; the value is only evaluated when qthread_initialize() is run.

Return Value

On success, the thread is spawned and 0 is returned. On error, a non-zero error code is returned.

Errors

ENOMEM
Not enough memory could be allocated.

See Also

qthread_migrate_to(3)


Table of Contents