MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Memory::MPSCPolicy Struct Reference

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
 

Detailed Description

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:

  • Storage MUST be FixedStorage (compile-time capacity, power of 2).
  • Single consumer only.
  • Multiple concurrent producers are safe.

Not suitable for:

  • Multiple concurrent consumers.
  • DynamicStorage (ready flag array is fixed at compile time).

Approximate metrics:

  • size() and empty() compare claim_index to read_index. A slot claimed but not yet written counts as occupied. Both are safe to call but may overcount transiently under concurrent push.

Definition at line 284 of file RingBuffer.hpp.


The documentation for this struct was generated from the following file: