Feature request: disruptor pattern FIFO

This https://lmax-exchange.github.io/disruptor/ would be really handy sometimes :slight_smile:

It’s a multi-producer, multi-consumer lock-free FIFO.

1 Like

This is a java library right? Doesn’t boost have a multi-producer, multi-consumer lock-free FIFO? I’m not saying that people should use it, but it might be good as a reference.

Seems there are at least 3 implementations of this one:

I also found this:

Which I might try…it seems well documented with benchmarks:


This one is a pretty small implementation:

I bench marked it against the moodycamel one some time ago and for my use case at the time it was almost exactly the same speed and the API is simpler (the moodcamel one will probably be faster in some cases).

1 Like

Presumably much of the cache_line padding stuff in there can now be replaced by alignas with C++11. What’s pad3 trying to achieve though?

I’m pretty sure that the reason for all of these pads is not alignment but to avoid false sharing. e.g., to prevent the consumer thread from having to reload a cacheline containing one member if the producer thread has written to an adjacent member. Pads 0 and 3 are presumably to ensure that this object’s members are at least a cache line away from other data too.

I also wish something like this existed in JUCE

This is definitely about false sharing. I think alignas will work to replace everything other than Pad 3, and presumably use slightly less memory as well.

juce::AbstractFifo doesn’t do this for the two juce::Atomics … i wonder how much difference it’d make. We use it in a few places. I might investigate for curosity!