An Elementary Introduction to Pthreads

Vijay Sonnad
IBM Corporation
Austin, Texas 78758
USA


Table of Contents

 
  1. What Is A Thread?
  2. What Are Pthreads?
  3. The Pthreads API
  4. Classification Of Pthreads Calls
  5. Simple Explanation Of A Mutex
  6. Simple Explanation Of Condition Variables
  7. Informal Classification Of Pthreads Functions
  8. Example program 1( from a book about threads)
  9. Example program 2( from a book about threads)
  10. Example program 3 (modified from the previous--> you can really see the the effect of mutex if you run this and the next)
  11. Example program 4

What Is A Thread?

 

What Are Pthreads?

 

The Pthreads API

 

Classification Of Pthreads Calls

 

Simple Explanation Of A Mutex

 

Simple Explanation Of Condition Variables

 

Informal Classification Of Pthreads Functions

 
  1. Pthread Functions
    1. Basic thread management
      1. pthread_create -- Creates threads
      2. pthread_exit -- Exits a thread
      3. pthread_join -- Joins with a thread
      4. pthread_once -- Executes only once
      5. pthread_kill -- Kills a thread
      6. pthread_self -- Provides handle of calling thread
      7. pthread_equal -- Checks for equality of two threads
      8. pthread_yield -- Yields to others of same priority
      9. pthread_detach -- Detaches a thread
    2. Thread-specific data
      1. pthread_key_create
      2. pthread_key_delete
      3. pthread_getspecific
      4. pthread_setspecific
    3. Thread cancellation
      1. pthread_cancel
      2. pthread_cleanup_pop
      3. pthread_cleanup_push
      4. pthread_setcancelstate
      5. pthread_getcancelstate
      6. pthread_testcancel
    4. Thread scheduling
      1. pthread_getschedparam
      2. pthread_setschedparam
    5. Signals
      1. pthread_sigmask
  2. Pthread Attribute Functions
    1. Basic management
      1. pthread_attr_init
      2. pthread_attr_destroy
    2. Detachable or joinable
      1. pthread_attr_setdetachstate
      2. pthread_attr_getdetachstate
    3. Specifying stack information
      1. pthread_attr_getstackaddr
      2. pthread_attr_getstacksize
      3. pthread_attr_setstackaddr
      4. pthread_attr_setstacksize
    4. Thread scheduling attributes
      1. pthread_attr_getschedparam
      2. pthread_attr_setschedparam
      3. pthread_attr_getschedpolicy
      4. pthread_attr_setschedpolicy
      5. pthread_attr_setinheritsched
      6. pthread_attr_getinheritsched
      7. pthread_attr_setscope
      8. pthread_attr_getscope
  3. Mutex Functions
    1. Basic mutex management
      1. pthread_mutex_init
      2. pthread_mutex_destroy
      3. pthread_mutex_lock
      4. pthread_mutex_unlock
      5. pthread_mutex_trylock
    2. Priority management
      1. pthread_mutex_setprioceiling
      2. pthread_mutex_getprioceiling
  4. Mutex Attribute Functions
    1. Basic mutex management
      1. pthread_mutexattr_init
      2. pthread_mutexattr_destroy
    2. Sharing
      1. pthread_mutexattr_getpshared
      2. pthread_mutexattr_setpshared
    3. Protocol attributes
      1. pthread_mutexattr_getprotocol
      2. pthread_mutexattr_setprotocol
    4. Priority management
      1. pthread_mutexattr_setprioceiling
      2. pthread_mutexattr_getprioceiling
  5. Condition Variable Functions
    1. Basic condition variable management
      1. pthread_cond_init
      2. pthread_cond_destroy
      3. pthread_cond_signal
      4. pthread_cond_broadcast
      5. pthread_cond_wait
      6. pthread_cond_timedwait
  6. Condition variable Attribute Functions
    1. Basic mutex management
      1. pthread_condattr_init
      2. pthread_condattr_destroy
    2. Sharing
      1. pthread_condattr_getpshared
      2. pthread_condattr_setpshared