Expand description
Asynchronous synchronization primitives
Synchronization primitives are tools for implementing synchronization between tasks: to control which tasks can run at any given time, and in what order, and to coordinate tasks’ access to shared resources. Typically, this synchronization involves some form of waiting. In asynchronous systems, synchronization primitives allow tasks to wait by yielding to the runtime scheduler, so that other tasks may run while they are waiting. This module provides asynchronous implementations of common synchronization primitives.
The following synchronization primitives are provided:
Mutex
: a fairly queued, asynchronous mutual exclusion lock, for protecting shared dataRwLock
: a fairly queued, asynchronous readers-writer lock, which allows concurrent read access to shared data while ensuring write access is exclusiveSemaphore
: an asynchronous counting semaphore, for limiting the number of tasks which may run concurrentlyWaitCell
, a cell that stores a single waiting task’sWaker
, so that the task can be woken by another task,WaitQueue
, a queue of waiting tasks, which are woken in first-in, first-out orderWaitMap
, a set of waiting tasks associated with keys, in which a task can be woken by its key
Note: maitake
’s synchronization primitives do not require the
maitake
runtime, and can be used with any async executor. Therefore,
they are provided by a separate maitake-sync
crate, which can be
used without depending on the rest of the maitake
runtime. This module
re-exports these APIs from maitake-sync
.
Modules§
- mutex
- An asynchronous mutual exclusion lock.
- rwlock
- An asynchronous readers-writer lock.
- semaphore
- An asynchronous counting semaphore.
- spin
- Synchronous spinning-based synchronization primitives.
- util
- Reusable utilities for synchronization primitives.
- wait_
cell - An atomically registered
Waker
, for waking a single task. - wait_
map - A map of
Waker
s associated with keys, so that a task can be woken by key. - wait_
queue - A queue of waiting tasks that can be woken in first-in, first-out order (or all at once).
Structs§
- Closed
- An error indicating that a
WaitCell
,WaitQueue
orSemaphore
was closed while attempting to register a waiting task. - Mutex
- An asynchronous mutual exclusion lock 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. - Owned
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. - Owned
RwLock Read Guard - Owned RAII structure used to release the shared read access of a
RwLock
when dropped. - Owned
RwLock Write Guard - Owned RAII structure used to release the exclusive write access of a
RwLock
when dropped. - RwLock
- An asynchronous readers-writer lock.
- RwLock
Read Guard - RAII structure used to release the shared read access of a
RwLock
when dropped. - RwLock
Write Guard - RAII structure used to release the exclusive write access of a
RwLock
when dropped. - Semaphore
- An asynchronous counting semaphore.
- Wait
Cell - An atomically registered
Waker
. - WaitMap
- A map of
Waker
s associated with keys, allowing tasks to be woken by their key. - Wait
Queue - A queue of waiting tasks which can be woken in first-in, first-out order, or all at once.
Type Aliases§
- Wait
Result - The result of waiting on a
WaitQueue
orSemaphore
.