Expand description
A library that provides both sync and unsync versions of common synchronization primitives.
§Example
If you’re a library author, a common pattern is to provide a feature gate that let users to choose whether they want multithread or not:
# cargo.toml
[dependencies]
synchrony = { version = "0.1.0", feature = ["mutex"] }
[features]
sync_foo = []and in your code:
ⓘ
#[cfg(feature = "sync_foo")]
use synchrony::sync;
#[cfg(not(feature = "sync_foo"))]
use synchrony::unsync as sync;
struct Foo {
lock: sync::mutex::Mutex,
count: sync::atomic::AtomicUsize,
}Or you can also hand-pick sync/unsync primitives:
ⓘ
use synchrony::*;
let unsync_lock = unsync::bilock::BiLock::new(42);
let sync_counter = sync::atomic::AtomicUsize::new(42);