Single-header C90 collection of synchronization primitives; Cort Stratton (2015).
npm install cds_sync.ccds_sync
========
This
single header file
C90 library provides a portable collection of synchronization
primitives for use in multithreaded programming - by Cort Stratton. 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.
Installation
------------
Run:
``sh
`
$ npm i cds_sync.c
cds_sync.h
And then include as follows:
`
c
`
// main.c
#define CDS_SYNC_IMPLEMENTATION
#include
int main() { / ... / }
node_modules/cds_sync.c
Finally, compile while adding the path to your compiler's include paths.
`
bash
`
$ clang -I./node_modules/cds_sync.c main.c # or, use gcc
$ gcc -I./node_modules/cds_sync.c main.c
`
You may also use a simpler approach with the cpoach tool, which automatically adds the necessary include paths of all the installed dependencies for your project.
bash
`
$ cpoach clang main.c # or, use gcc
$ cpoach gcc main.c
#define`s if desired.
Key Features / Design Goals
---------------------------
- 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
- No (mandatory) external dependencies. Only standard C library
functions are used, and even those can be overriden with custom
implementations through
- Dirt-simple integration. Just a single header file to include in
your project.
- Public domain license terms.
Acknowledgements
----------------
- 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.


