bare-atomics
Reference for bare-atomics: native cross-thread synchronization primitives for Bare—mutex, semaphore, condition variable, and barrier.
bare-atomics provides native synchronization primitives for coordinating Bare threads. Each primitive exposes a transferable handle, so it can be shared with another thread and reconstructed with from(). It's a native addon and requires Bare >=1.2.0.
npm i bare-atomicsAPI
Mutex
const mutex = new Mutex([options]) · Mutex.from(handle[, options])
A mutual-exclusion lock: mutex.held, mutex.lock(), mutex.tryLock(), mutex.unlock(), mutex.destroy(), and mutex.handle.
Semaphore
const semaphore = new Semaphore(value) · Semaphore.from(handle)
A counting semaphore: semaphore.wait(), semaphore.tryWait(), semaphore.post(), semaphore.destroy(), and semaphore.handle.
Condition
const condition = new Condition() · Condition.from(handle)
A condition variable: condition.wait(mutex[, timeout]), condition.signal(), condition.broadcast(), condition.destroy(), and condition.handle.
Barrier
const barrier = new Barrier(count) · Barrier.from(handle)
A thread barrier: barrier.wait(), barrier.destroy(), and barrier.handle.
See also
- Bare runtime API—
Bare.Thread, the threads these coordinate. bare-channelandbare-broadcast-channel—higher-level message passing between threads.- Bare modules—the full
bare-*catalog.