Module sync::lockfree
LFQueue<T>: lock-free SPSC ring buffer queue
struct LFQueue<long long> q = std::LFQueue::new(8UL); // cap rounded up to a power of two
q.enqueue(5LL); // producer thread; 0 if full
?long long v = q.dequeue(); // consumer thread; null if empty
q.destroy();
Exactly one producer and one consumer (see mpsc.h for several producers). head/tail are monotonically increasing element counters updated with atomic stores; only the slot index is 'counter & (cap - 1)'. That tells "full" (head - tail == cap) apart from "empty" (head == tail) without sacrificing a slot, so all 'cap' elements are usable.
Structs
| LFQueue |