Skip to main content

Module mpmc_disruptor

Module mpmc_disruptor 

Source
Expand description

Multi-producer multi-consumer ring with sequence-barrier gating.

Based on the LMAX Disruptor pattern. Three sequences:

  • producer_cursor: next index a producer will try to claim. CAS’d up by try_claim.
  • published[idx]: per-slot atomic published flag. A claimed slot is marked published once the producer finishes writing.
  • consumer_cursor[i]: per-consumer next index to read. Owned by that consumer; advanced after a successful read.

Producer gating: a producer cannot claim slot s until the slowest consumer has passed s - capacity. Consumer gating: a consumer cannot read slot s until published[s & mask] matches the round it’s in. published stores the absolute sequence value of the last publish so producers and consumers can distinguish round N from round N+1 in the same slot.

Independent of the base SPSC structures - this is a separate ring with different invariants.

Structs§

DisruptorConsumer
One consumer side. Each consumer sees every published item.
DisruptorProducer
Multi-producer side. Cheap to Clone; share across producer threads.
MpmcDisruptor
Builder + constructor. Use MpmcDisruptor::with_consumers.