Module sync
Available on crate feature
sync only.Expand description
Synchronization primitives.
This module re-exports synchronization primitives from the standard library
and from tokio.
This module renames tokio::sync::Mutex and tokio::sync::RwLock to
AsyncMutex and AsyncRwLock respectively to avoid confusion with the
standard library’s Mutex and RwLock types.
Async and sync mutexes and rwlocks are not interchangeable.
As a rule of thumb, if a lock is never held across an .await point, it’s
likely more efficient to use a sync lock. Async locks have more overhead.
Modules§
- atomic
- Atomic types
- broadcast
- A multi-producer, multi-consumer broadcast queue. Each sent value is seen by all consumers.
- mpsc
- A multi-producer, single-consumer queue for sending values between asynchronous tasks.
- oneshot
- A one-shot channel is used for sending a single message between
asynchronous tasks. The
channelfunction is used to create aSenderandReceiverhandle pair that form the channel. - watch
- A multi-producer, multi-consumer channel that only retains the last sent value.
Structs§
- Arc
- A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
- Async
Mutex - An asynchronous
Mutex-like type. - Async
Once Lock - A thread-safe cell that can be written to only once.
- Async
RwLock - An asynchronous reader-writer lock.
- Barrier
std - A barrier enables multiple threads to synchronize the beginning of some computation.
- Condvar
std - A Condition Variable
- Lazy
Lock std - A value which is initialized on the first access.
- Mutex
std - A mutual exclusion primitive useful for protecting shared data
- Mutex
Guard std - An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked.
- Once
std - A low-level synchronization primitive for one-time global execution.
- Once
Lock std - A synchronization primitive which can nominally be written to only once.
- RwLock
std - A reader-writer lock
- RwLock
Read Guard std - RAII structure used to release the shared read access of a lock when dropped.
- RwLock
Write Guard std - RAII structure used to release the exclusive write access of a lock when dropped.
- Weak
Weakis a version ofArcthat holds a non-owning reference to the managed allocation.
Enums§
- Async
Once Lock SetError - Errors that can be returned from
OnceCell::set.