man rthread (Fonctions bibliothèques) - Roy threading API

NAME

rthread - Roy threading API

SYNOPSIS

#include <roy.h>

RThread * rthread_create (RThreadFunction *function, void *user_data);

void rthread_exit (void *user_data);

void rthread_free (RThread *thread);

int rthread_waitfor (RThread *thread, void **user_data);

int rthread_err (RThread *thread);

char * rthread_strerror (RThread *thread);

void rthread_yield_if_coop ();

DESCRIPTION

Roy implements a very thin, portable interface to threads that works on any UNIX system with pthreads or the ability to use PTH, as well as Win32 systems. The API is fairly small for now but will likely be expanded in future releases as requirements expand.

By default, rthread uses pthreads on UNIX systems, but may also use GNU PTH as a fallback, or as an alternative for pthreads. See http://www.gnu.org/software/pth for details on PTH. pthreads can be disabled at compile time using the --without-pthreads argument to configure.

rthread_create(3) creates a new thread, running function. user_data is passed to function as the first argument. The definition for the function pointer is:

typedef void * (RThreadFunction) (void *user_data);

So a typical declaration for this function might look like:

void * new_thread (void *data);

The return value can be retrieved by another thread by using rthread_waitfor(3).

rthread_exit(3) causes a thread to terminate. The user_data argument may be set and gathered in another thread by using rthread_waitfor(3).

rthread_free(3) should always be called on the RThread structure returned by rthread_create(3). This can be done at any time and will not affect the running of the thread, except that this handle may be needed later for various operations.

rthread_waitfor(3) waits for the specified thread to exit or return. The user_data argument will then be set to the value returned or specified in rthread_exit(3).

rthread_err(3) returns non-zero if an error occured in the last operation performed on thread.

rthread_strerror(3) should be used to print out any errors that have occured on a thread. thread will contain the error code of the last error.

rthread_yield_if_coop(3) will cause a yield of the current threads execution to another thread IF the underlying threading system is cooperative. This includes PTH and the pthread compatibility library it provides.

RETURN VALUE

rthread_create(3) returns a valid RThread structure which can be used by rthread_waitfor(3) to gather return information and as a syncronization facility. In the event of an error, the structure is flagged internally. This condition can be checked using rthread_err(3).

rthread_waitfor(3) returns non-zero if an error occurrs. This error can be retrieved using rthread_strerror(3) and can also be checked with rthread_err(3).

rthread_err(3) returns non-zero if an error had recently occured in an rthread function call.

rthread_strerror(3) returns a static string containing the text of the error message.

All other functions do not return a value.

SEE ALSO