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:
- AsyncMutex
- AsyncRwLock
- UpgradableAsyncRwLock when you need to read first and then conditionally upgrade to write without allowing another writer to slip in between.
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§
- Async
Mutex - An asynchronous
Mutex-like type. - Async
Mutex Guard - A handle to a held
Mutex. The guard can be held across any.awaitpoint as it isSend. - Async
RwLock - An asynchronous reader-writer lock.
- Async
RwLock Read Guard - RAII structure used to release the shared read access of a lock when dropped.
- Async
RwLock Write Guard - 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.
- Upgradable
Async RwLock - A Tokio-based async rwlock with an upgradable read mode.
- Upgradable
Async RwLock Upgradable Read Guard - Upgradable read guard for UpgradableAsyncRwLock.
- Upgradable
Async RwLock Write Guard - Exclusive write guard for UpgradableAsyncRwLock.
Type Aliases§
- Mutex
- A mutual exclusion primitive useful for protecting shared data
- Mutex
Guard - 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
- RwLock
Read Guard - RAII structure used to release the shared read access of a lock when dropped.
- RwLock
Write Guard - RAII structure used to release the exclusive write access of a lock when dropped.