google/nsync
Freensync is a C library that exports various synchronization primitives, such as mutexes
About google/nsync
nsync is a C library developed by Google that provides efficient synchronization primitives for multithreaded programming. It offers mutexes (reader-writer locks), condition variables, run-once initialization, waitable counters (useful for barriers), waitable bits (for cancellation or other conditions), and conditional critical sections. The library is designed to be portable, working on Unix-like systems and Windows, and can be compiled with a C90 compiler assuming atomic operations are available. nsync locks and condition variables occupy only two words each, making them memory-efficient. Conditional critical sections simplify usage by eliminating the need for explicit while loops and wake signals, though they may be slower under many false conditions. The library is not an official Google product.
Key Features
Pros & Cons
- Reader-writer locks are as efficient as mutexes but allow concurrent reads
- Conditional critical sections eliminate the need for explicit while loops and wake signals
- Very small memory footprint (two words per lock/condition variable)
- Portable across Unix-like and Windows platforms
- Can be compiled with C90, C11, C++11, or C++14
- Supports cancellation of waits, unlike pthread thread cancellation
- Conditional critical sections may be slower if many threads wait on many distinct false conditions
- Not as widely known as pthreads; may require learning
- No class-based C++ interface; uses C-style API