The original Pthreads API was defined in the ANSI/IEEE POSIX 1003.1 - 1995 standard. The POSIX standard has continued to evolve and undergo revisions, including the Pthreads specification.
Copies of the standard can be purchased from IEEE or downloaded for free from other sites online.
The subroutines which comprise the Pthreads API can be informally grouped into four major groups:
Naming conventions: All identifiers in the threads library begin with pthread_
. Some examples are shown below.
Routine Prefix | Functional Group |
---|---|
pthread_ | Threads themselves and miscellaneous subroutines |
pthread_attr_ | Thread attributes objects |
pthread_mutex_ | Mutexes |
pthread_mutexattr_ | Mutex attributes objects |
pthread_cond_ | Condition variables |
pthread_condattr_ | Condition attributes objects |
pthread_key_ | Thread-specific data keys |
pthread_rwlock_ | Read/write locks |
pthread_barrier_ | Synchronization barriers |
The concept of opaque objects pervades the design of the API. The basic calls work to create or modify opaque objects - the opaque objects can be modified by calls to attribute functions, which deal with opaque attributes.
The Pthreads API contains around 100 subroutines. This tutorial will focus on a subset of these - specifically, those which are most likely to be immediately useful to the beginning Pthreads programmer.
For portability, the pthread.h
header file should be included in each source file using the Pthreads library.
The current POSIX standard is defined only for the C language. Fortran programmers can use wrappers around C function calls. Some Fortran compilers may provide a Fortran pthreads API.
A number of excellent books about Pthreads are available. Several of these are listed in the References section of this tutorial.