qthread_t *
qthread_prepare(qthread_f *f, const void *arg, aligned_t *ret);
qthread_t
*
qthread_prepare_for(qthread_f *f, const void *arg, aligned_t *ret, const
qthread_shepherd_id_t shepherd);
The first argument to these functions, f, is a function that will be run to completion by the created qthread. (Note that f is a qthread_f and not a qthread_t.) 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(qthread_t *me, void *arg);
The qthread_prepare_for() function prepares the qthread for the specified shepherd.
When a qthread_t is returned, it is not scheduled to run, and must be passed to either qthread_schedule() or qthread_schedule_on().
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()). 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() on the ret pointer.