Skip to main content

Module mutex

Module mutex 

Source
Expand description

Async mutex — cooperative mutual exclusion for async tasks.

Unlike std::sync::Mutex, locking suspends the calling task (yields back to the executor) instead of blocking the OS thread. This is critical inside async contexts where blocking would starve other tasks sharing the thread.

§Design

  • Inner value protected by a std::sync::Mutex for the critical section of updating waker queues and the locked flag.
  • A VecDeque<Waker> wait queue ensures FIFO fairness across contenders.
  • MutexGuard drops the lock and wakes the next waiter on Drop.

Structs§

LockFuture
Future returned by Mutex::lock.
Mutex
Async-aware mutual exclusion primitive.
MutexGuard
RAII guard that releases the async lock on drop and wakes the next waiter.