PREV UP NEXT StackThreads/MP: version 0.77 User's Guide

3.3: Synchronization

StackThreads/MP provides standard synchronization primitives including mutex, semaphore, and condition variables. Mutex and condition variables behave like their Pthread counter part, and semaphore (not supported by Pthread) behaves like its Solaris thread counter part. StackThreads/MP also supports a very commonly used producer-consume synchronization primitive, called join counter.

All these waiting primitives (mutex lock, semaphore wait, condition wait, and join counter wait) block the currently running thread (the thread created by ST_THREAD_CREATE) and schedule another thread, when the waiting condition is not immediately satisfied.

NOTE: In the following description, we say "xxx signals an error, when ... ". The meaning of this statement depends on how the library was compiled. These procedures are defined in file src/st_sync.c in StackThreads/MP distribution and the file contains a macro #define ST_DIE_ON_ERROR 1 at the head of it. When this flag is set to 1 (the default), "signals an error" means the application will die when an error occurs (It has nothing to do with UNIX signals). This is useful when debugging (and also when your application is stable enough not to perform such an error). When this flag is zero, it simply means the procedure returns an error value (ST_FAULT).

  • Join Counter
  • Semaphore
  • Mutex
  • Condition Variable