Skip to content
CryoCryo home
StdlibConcurrency

sync

Synchronization primitives. Cross-platform: pthread primitives on POSIX, the Win32 equivalents (SRWLOCK, condition variables) on Windows, selected by target.

public module sync::atomic;
public module sync::mutex;
public module sync::rwlock;
public module sync::condvar;
public module sync::once;
public module sync::barrier;
public module sync::mpsc;
FileWhat it holdsImport
atomicAtomic<T>, MemoryOrder, fenceimport std::sync::atomic;
mutexMutex<T, A>, MutexGuardimport std::sync::mutex;
rwlockRwLock<T, A> and its guardsimport std::sync::rwlock;
condvarCondVarimport std::sync::condvar;
onceOnceimport std::sync::once;
barrierBarrierimport std::sync::barrier;
mpscchannel, Sender, Receiverimport std::sync::mpsc;

Sharing any of these across threads means wrapping them in Arc. The guard types are !Send by design — a lock guard must be released by the thread that took it. See Send and Sync.

Every lock-like type here follows the same shape: a heap-allocated *Inner holding the platform primitive's raw bytes (pthread_buf) beside the guarded value, and a handle that is just a pointer to it. The pthread object's address therefore stays stable while other threads hold or wait on it — moving a pthread mutex after init is undefined behaviour — while the handle itself moves freely.