Skip to main content

Module sync

Module sync 

Source
Expand description

Utilities for working with synchronization primitives.

§Choosing A Lock

Prefer blocking locks for shared data:

Use async locks only when you must hold a lock guard across an .await point:

Async locks are more expensive and should generally be reserved for coordination around asynchronous I/O resources. For plain in-memory data, blocking locks are usually the right default.

Do not hold blocking lock guards across .await.

Async lock guards may span .await when needed, but keep those critical sections as small as possible because long-held guards increase contention and deadlock risk.

Structs§

AsyncMutex
An asynchronous Mutex-like type.
AsyncMutexGuard
A handle to a held Mutex. The guard can be held across any .await point as it is Send.
AsyncRwLock
An asynchronous reader-writer lock.
AsyncRwLockReadGuard
RAII structure used to release the shared read access of a lock when dropped.
AsyncRwLockWriteGuard
RAII structure used to release the exclusive write access of a lock when dropped.
Condvar
A Condition Variable
Once
A synchronization primitive which can be used to run a one-time initialization. Useful for one-time initialization for globals, FFI or related functionality.
UpgradableAsyncRwLock
A Tokio-based async rwlock with an upgradable read mode.
UpgradableAsyncRwLockUpgradableReadGuard
Upgradable read guard for UpgradableAsyncRwLock.
UpgradableAsyncRwLockWriteGuard
Exclusive write guard for UpgradableAsyncRwLock.

Type Aliases§

Mutex
A mutual exclusion primitive useful for protecting shared data
MutexGuard
An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
RwLock
A reader-writer lock
RwLockReadGuard
RAII structure used to release the shared read access of a lock when dropped.
RwLockWriteGuard
RAII structure used to release the exclusive write access of a lock when dropped.