Threads -- Thread Support Library

The Threads library provides a C++ wrapper around the pthreads library. It supports thread management, mutex semaphores with resource-allocation-as-initialization lock management, condition variables, mutex-protected condition variables, multi-thread synchronization points, thread-local storage, and a generic class providing lock-free one-way asynchronous communication using triple buffers.

Header Files

Config.h
Config.h defines configuration-dependent macros used by the Threads library. It should be included by client code that wants to make decisions based on the availability of optional features.
Thread.h
Thread is a class representing a thread of execution. It can start threads from C functions or C++ methods, each with optional additional data passed to the thread function/method. Non-detached threads are automatically terminated (cancelled and joined) when their Thread object is destroyed.
Spinlock.h
Spinlock is a class representing a light-weight mutual-exclusion semaphor implemented via busy waiting. Spinlock has an embedded Lock class that allows expressing spinlock locking/unlocking as object construction/destruction. Spinlock should not be used if there is the potential for any user holding a lock for an extended period of time, i.e., it should only be used to protect very short critical sections.
Mutex.h
Mutex is a class representing a mutual-exclusion semaphor. Mutex has an embedded Lock class that allows expressing mutex locking/unlocking as object construction/destruction.
Cond.h
Cond is a class representing a condition variable, i.e., a semaphore that threads can block on and that can be used to signal events to interested threads asynchronously. It is assumed that each condition variable is protected by a mutual-exclusion semaphore represented by a Mutex object to prevent race conditions.
MutexCond.h
MutexCond is a class representing the combination of a condition variable with a dedicated mutex semaphore.
Barrier.h
Barrier is a class implementing synchronization points where a fixed number of threads must come together before any can proceed.
Local.h
Local is a templatized class wrapping the parameter data type into a thread-local storage model using the POSIX TLS interface. Local variables are meant to be declared with static storage type, i.e., either as global variables, function-static variables, or static class elements. Any thread-local storage mechanism provided by the host compiler and run-time environment, such as gcc's __thread extension, yield much better performance and should be used instead.
Atomic.h
Atomic is a templatized class to perform atomic operations on integral data types. If the local runtime environment does not offer CPU support for atomic operations, they will be simulated using busy-wait (if available) or regular mutual exclusion semaphores.
RefCounted.h
RefCounted is a thread-safe version of the Misc::RefCounted base class for reference counted objects to implement simple automatic garbage collection. It uses a mutex to serialize access to a reference counted object's counter.
RefCountedArray
RefCountedArray is a thread-safe verion of the Misc::RefCountedArray class representing shared C-style fixed-size arrays using a copy-on-write mechanism. It uses a mutex to serialize access to an array's reference counter.
TripleBuffer.h
TripleBuffer is a class implementing the triple buffer communications pattern, where a consumer can read the most recent in a stream of values produced by a producer, without requiring synchronization between the two entities.
Queue.h
Queue is a simple unlimited-size queue to communicate data between one or more producers and one or more consumers.
LimitedQueue.h
LimitedQueue is a simple limited-size queue to communicate data between one or more producers and one or more consumers.
RingBuffer.h
RingBuffer is a class implementing the pipe communications pattern, where a consumer can read a stream of values produced by a producer.
DropoutBuffer.h
DropoutBuffer is a generalization of TripleBuffer: Instead of only retaining one most recent value to read, it retains up to a preset number of most recent values. Unlike TripleBuffer, it requires some synchronization between producer and consumer.
EventDispatcher.h
EventDispatcher centralizes distributing asynchronous events from multiple sources of different types to multiple listeners.