Module maitake::sync

source ·
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 data
  • RwLock: a fairly queued, asynchronous readers-writer lock, which allows concurrent read access to shared data while ensuring write access is exclusive
  • Semaphore: an asynchronous counting semaphore, for limiting the number of tasks which may run concurrently
  • WaitCell, a cell that stores a single waiting task’s Waker, so that the task can be woken by another task,
  • WaitQueue, a queue of waiting tasks, which are woken in first-in, first-out order
  • WaitMap, 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

Structs

Type Aliases