Feature request: disruptor pattern FIFO


#1

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

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


#2

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.


#3

Seems there are at least 3 implementations of this one:
https://www.google.co.uk/search?q=distruptor+c%2B%2B

I also found this:

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

http://moodycamel.com/blog/2014/a-fast-general-purpose-lock-free-queue-for-c++#benchmarks


#4

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).


#5

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?


#6

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.


#7

I also wish something like this existed in JUCE


#8

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!