Chapter 14. POSIX Threads

Table of Contents
14.1. Initialization Functions
14.2. Create and Destroy Functions
14.3. Scheduling Functions
14.4. Timing Functions
14.5. Pthread Attribute Functions
14.6. Pthread Cond Functions
14.7. Pthread Mutex Functions
14.8. Miscellaneous Functions

The XGC library supports a subset of POSIX Threads as defined in IEEE 1003.1c-1995. It provides the majority of the POSIX functions for threads, mutexes, and condition variables, as well as pthread_once, thread-specific data, and cleanup handlers. There is an additional function to make a thread wait for an interrupt.

The relevant Pthread attribute functions are provided, but there are no useful Mutex attributes or Condition Variable attributes and hence no associated functions; the attr parameter to pthread_mutex_init or to pthread_cond_init must be null.

There is currently no pthread_key_delete function, nor is the asynchronous pthread_cancel or the associated functions provided.

Programs using Pthreads must call pthread_init before calling any other Pthread function. Termination of the main program will cause the termination of all threads, unless exit is made via pthread_exit. (But there is no need for other threads to finish with pthread_exit).

Scheduling is always FIFO within priority.

The POSIX functions sleep, nanosleep, and clock_gettime are provided, with a resolution of 0.01 seconds. The timeout parameter of pthread_cond_timedwait requires an absolute time that is based on clock_gettime.

The implementation of signals is the ANSI C one, with just signal and raise, not the POSIX one with thread-specific masks. Synchronous interrupts, such as overflow, are mapped onto the appropriate ANSI C signal, and raised in the context of the current thread, which is the one that contains the fault.

Asynchronous interrupts can be handled by user supplied interrupt functions, connected by the handler function, and will run outside the context of any thread. User's handlers must save and restore the global errno if there is any risk of them altering it.

Alternatively, a thread can wait for one or more interrupts by using the intwait function, which takes a mask saying which interrupts it is waiting for, and returns a code saying which one was received. At most one thread can wait for each interrupt at any one time.

14.1. Initialization Functions

14.1.1. The pthread_init function

Synopsis
#include <pthread.h>

void pthread_init ( void );

Description

The pthread_init function must be called before any other function in the POSIX Threads library.

Implementation Notes

None.