SP Parallel Programming II Workshop
p o s i x     t h r e a d s     p r o g r a m m i n g



  Table of Contents
  1. Pthreads Overview
    1. What Is A Thread?
    2. What Are Pthreads?
    3. Why Pthreads?
    4. Designing Threaded Programs
  2. The Pthreads API
  3. Thread Management
    1. Creating Threads
    2. Terminating Thread Execution
    3. Example: Pthread Creation and Termination
    4. Passing Arguments To Threads
    5. Thread Identifiers
    6. Joining Threads
    7. Detaching / Undetaching Threads
    8. Example: Joining Threads
  4. Mutex Variables
    1. Mutex Variables Overview
    2. Creating / Destroying Mutexes
    3. Locking / Unlocking Mutexes
    4. Example: Using Mutexes
  5. Condition Variables
    1. Condition Variables Overview
    2. Creating/Destroying Condition Variables
    3. Waiting / Signalling On Condition Variables
    4. Example: Using Condition Variables
  6. Pthreads, MPI, SMPs, AIX and IBM's PE
  7. Pthread Library Routines Reference
  8. References and More Information
  9. Exercise


 
 
Pthreads Overview Up to Table of Contents Down to What Are Pthreads?
What Is A Thread?


 
Pthreads Overview Up to What Is A Thread? Down to Why Pthreads?
What Are Pthreads?


 
Pthreads Overview Up to What Are Pthreads? Down to Designing Threaded Programs
Why Pthreads?


 
Pthreads Overview Up to Why Pthreads? Down to The Pthreads API
Designing Threaded Programs


 
The Pthreads API Up to Designing Threaded Programs Down to Thread Management

Note: IBM's API includes a Fortran interface which may be used for convenience at the price of portability.



 
 
Thread Management Up to The Pthreads API Down to Terminating Thread Execution
Creating Threads

Check your local implementation for limits on thread creation. For example, AIX 4.2 specifies a maximum of 512 threads per process with a default thread stack size of 56K bytes.


 
Thread Management Up to Creating Threads Down to Example: Pthread Creation and Termination
Terminating Thread Execution



 
Thread Management Up to Terminating Thread Execution Down to Passing Arguments To Threads
Example: Pthread Creation and Termination


 
Thread Management Up to Example: Pthread Creation and Termination Down to Thread Identifiers
Passing Arguments To Threads

Important: threads initially access their data structures in the parent thread's memory space. That data structure must not be corrupted/modified until the thread has finished accessing it.



 
Thread Management Up to Passing Arguments To Threads Down to Joining Threads
Thread Identifiers


 
Thread Management Up to Thread Identifiers Down to Detaching / Undetaching Threads
Joining Threads


 
Thread Management Up to Joining Threads Down to Example: Joining Threads
Detaching / Undetaching Threads

Current implementations differ in the default detached status at thread creation time. SGI for example, creates threads as joinable (undetached). IBM's AIX 4.2 implementation creates threads as unjoinable (detached) by default, whereas AIX 4.3 creates threads as joinable (undetached). The final standard specifies undetached as the default.


 
Thread Management Up to Detaching / Undetaching Threads Down to Mutex Variables
Example: Pthread Joining



 
 
Mutex Variables Up to Example: Joining Threads Down to Creating / Destroying Mutexes
Overview


 
Mutex Variables Up to Mutex Variables Overview Down to Locking / Unlocking Mutexes
Creating / Destroying Mutexes
Note: Your implementation may/may not provide the three optional mutex attributes. For example, in AIX 4.2 and 4.3 mutex attributes are not defined.


 
Mutex Variables Up to Creating / Destroying Mutexes Down to Example: Using Mutexes
Locking / Unlocking Mutexes


 
Mutex Variables Up to Locking / Unlocking Mutexes Down to Condition Variables
Example: Using Mutexes



 
 
Condition Variables Up to Mutex Variables Down to Pthreads, MPI, SMPs, AIX and IBM
Overview


 
Condition Variables Up to Condition Variables Overview Down to Waiting / Signalling On Condition Variables
Creating / Destroying Condition Variables

Check your implementation for the ability to use the condition variable attributes object. For example, in AIX 4.2 and 4.3 this option is not implemented and the value "NULL" should be used.



 
Condition Variables Up to Creating/Destroying Condition Variables Down to Example: Using Condition Variables
Waiting / Signalling On Condition Variables


 
Condition Variables Up to Waiting / Signalling On Condition Variables Down to Pthreads, MPI, SMPs, AIX and IBM
Example: Using Condition Variables


 
Pthreads, MPI, SMPs, AIX and IBM's PE Up to Example: Using Condition Variables Down to Pthread Library Routines Reference


 
Pthread Library Routines Reference Up to Pthreads, MPI, SMPs, AIX and IBM Down to References and More Information


 
References and More Information Up to Pthread Library Routines Reference