This single header file C90 library provides a portable collection of synchronization primitives for use in multithreaded programming. The following primitives are provided:
cds_sync_futex_t
-- A futex (fast userspace mutex), guaranteed to stay in userspace code unless a thread must be put to sleep or awakened.cds_sync_fusem_t
-- A fast userspace semaphore, guaranteed to stay in userspace code unless a thread must be put to sleep or awakened.cds_sync_monitor_t
-- A monitor, which bundles a condition variable and its associated mutex.cds_sync_eventcount_t
-- An event count which lets callers safely avoid waiting unless there's actually no work to do.cds_sync_monsem_t
-- A monitored semaphore, which builds on the basic semaphore by allowing a master thread to wait for the semaphore to have a certain positive non-zero value.cds_sync_barrier_t
-- Lets users specify a barrier that all threads must reach before any thread can proceed.
- Identical API on all supported platforms. The following
platforms are tested regularly:
- Microsoft Windows 7
- Visual Studio 2010
- Visual Studio 2012
- Visual Studio 2013
- Linux Mint
- LLVM/Clang 3.5
- gcc 4.8.4
- Apple OSX
- Apple LLVM/Clang 6.1.0
- Microsoft Windows 7
- No (mandatory) external dependencies. Only standard C library
functions are used, and even those can be overriden with custom
implementations through
#define
s if desired. - Dirt-simple integration. Just a single header file to include in your project.
- Public domain license terms.
- Sean Barrett: master of single-header C libraries.
- Charles Bloom: poster of sync primitives; ranter.
- Allen B. Downey: author of The Little Book of Semaphores.