Skip to main content

Module mpsc

Module mpsc 

Source
Expand description

A lock-free multi-producer, single-consumer queue: any thread pushes, one thread takes everything at once.

Producers push onto an atomic stack with one compare-and-swap; the consumer swaps the whole stack out in one atomic exchange and reverses it, so items come out in the order they were pushed (per producer, and in push order overall). There is no lock, so a producer never waits on the consumer or on another producer’s critical section, and nothing ever calls into the kernel. Taking the whole stack at once has no ABA problem: a node is only ever freed by the consumer after it left the shared stack.

The event loops use it for messages from other threads (Responder::send, offloaded jobs), together with crate::driver::Waker::post, which wakes a loop only when it is parked.

Structs§

Mpsc
The queue (see the module documentation).