Expand description
Lock-free MPMC bounded queue using a ring buffer with atomic operations.
This module implements a high-performance multi-producer, multi-consumer bounded queue that avoids mutexes on the hot path. Each slot has its own sequence number so producers and consumers can independently claim a slot without blocking one another.
§Algorithm
Each ring-buffer slot stores:
sequence: AtomicUsize— an ever-increasing stamp that encodes the slot state (empty/ready-to-read).value: UnsafeCell<MaybeUninit<T>>— the payload.
A producer:
- Atomically increments the shared
tail. - Waits (spin) until
slot.sequence == tail(the slot was last read bytail - capacityago, so it is now free). - Writes the value and sets
slot.sequence = tail + 1(signals the consumer that the slot is ready).
A consumer mirrors the process using head.
This is the classic Dmitry Vyukov MPMC queue design.
Structs§
- Lock
Free Queue - A bounded, lock-free multi-producer / multi-consumer queue.