A library that provides both sync and unsync versions of common synchronization primitives.
All of the following primitives are provided in both sync and unsync versions:
- Shared (
Rc/Arc) - Atomic Scalars
- Watch
- Waker Slot (
AtomicWakerand its unsync counterpart) - Mutex
- Async Mutex
- BiLock
- Flag (specialized
AtomicBool) - Event (
event-listenerandlocal-event) - Async Flag
This library includes built-in support for loom, a testing tool for concurrent Rust code that helps verify the correctness of concurrent algorithms.
When compiled with --cfg loom, the library automatically switches to use loom's implementations of synchronization primitives instead of the standard library versions. This enables you to:
- Detect data races and concurrency bugs
- Verify lock-free algorithms
- Test different thread interleavings exhaustively
For more information about loom and how to write loom tests, see the loom documentation.
The following types automatically use loom implementations when the loom cfg is enabled:
std::sync::atomic::*types (AtomicBool,AtomicUsize, etc.)std::sync::Arc→loom::sync::Arcstd::sync::Mutex→loom::sync::Mutexstd::cell::UnsafeCell→loom::cell::UnsafeCellstd::cell::Cell→loom::cell::Cell