Expand description
Async synchronization primitives.
This crate provides the following primitives:
Barrier- enables tasks to synchronize all together at the same time.Mutex- a mutual exclusion lock.RwLock- a reader-writer lock, allowing any number of readers or a single writer.Semaphore- limits the number of concurrent operations.
§Relationship with std::sync
In general, you should consider using std::sync types over types from this crate.
There are two primary use cases for types from this crate:
- You need to use a synchronization primitive in a
no_stdenvironment. - You need to hold a lock across an
.awaitpoint. (Holding anstd::synclock guard across an.awaitwill make your future non-Send, and is also highly likely to cause deadlocks.)
If you already use libstd and you aren’t holding locks across await points (there is a
Clippy lint called await_holding_lock that emits warnings for this scenario), you should
consider std::sync instead of this crate. Those types are optimized for the currently
running operating system, are less complex and are generally much faster.
In contrast, async-lock’s notification system uses std::sync::Mutex under the hood if
the std feature is enabled, and will fall back to a significantly slower strategy if it is
not. So, there are few cases where async-lock is a win for performance over std::sync.
Modules§
- futures
- Named futures for use with
async_lockprimitives.
Structs§
- Barrier
- A counter to synchronize multiple tasks at the same time.
- Barrier
Wait Result - Returned by
Barrier::wait()when all tasks have called it. - Mutex
- An async mutex.
- Mutex
Guard - A guard that releases the mutex when dropped.
- Mutex
Guard Arc - An owned guard that releases the mutex when dropped.
- Once
Cell - A memory location that can be written to at most once.
- RwLock
- An async reader-writer lock.
- RwLock
Read Guard - A guard that releases the read lock when dropped.
- RwLock
Read Guard Arc - An owned, reference-counting guard that releases the read lock when dropped.
- RwLock
Upgradable Read Guard - A guard that releases the upgradable read lock when dropped.
- RwLock
Upgradable Read Guard Arc - An owned, reference-counting guard that releases the upgradable read lock when dropped.
- RwLock
Write Guard - A guard that releases the write lock when dropped.
- RwLock
Write Guard Arc - An owned, reference-counted guard that releases the write lock when dropped.
- Semaphore
- A counter for limiting the number of concurrent operations.
- Semaphore
Guard - A guard that releases the acquired permit.
- Semaphore
Guard Arc - An owned guard that releases the acquired permit.