|
MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
|
Lock-free MPSC (Multi-Producer Single-Consumer) concurrency. More...
#include <RingBuffer.hpp>
Collaboration diagram for MayaFlux::Memory::MPSCPolicy:Classes | |
| struct | State |
Static Public Attributes | |
| static constexpr bool | is_mpsc = true |
| static constexpr bool | is_thread_safe = true |
| static constexpr bool | requires_fixed_storage = true |
| static constexpr bool | requires_trivial_copyable = false |
Lock-free MPSC (Multi-Producer Single-Consumer) concurrency.
Producers claim a slot atomically via fetch_add on a shared claim index, write into that slot, then mark it ready via a per-slot atomic flag. The single consumer spins on the ready flag of its current read slot before consuming - the spin is bounded because producers only stall the consumer for the duration of one slot write, not an unbounded critical section.
Push is wait-free per producer in the uncontended case (one fetch_add, one store, one flag set). Under contention producers do not interfere with each other's slots - each owns its claimed index exclusively.
Pop is wait-free when the ready flag is already set. It spins only if a producer has claimed the slot but not yet finished writing - this window is a handful of cycles (the slot assignment), not a lock hold.
Requirements:
Not suitable for:
Approximate metrics:
Definition at line 284 of file RingBuffer.hpp.