# Feature request: disruptor pattern FIFO

**URL:** <https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991>\
**Category:** Feature Requests\
**Created:** [August 31, 2017, 9:30am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991 "2017-08-31T09:30:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [August 31, 2017, 9:30am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/1 "2017-08-31T09:30:28Z")

</div>

This [https://lmax-exchange.github.io/disruptor/](https://lmax-exchange.github.io/disruptor/) would be really handy sometimes 🙂

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

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [September 6, 2017, 11:29am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/2 "2017-09-06T11:29:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [September 6, 2017, 12:08pm UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/3 "2017-09-06T12:08:30Z")

</div>

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

I also found this:

> **[cameron314/concurrentqueue](https://github.com/cameron314/concurrentqueue)**
>
> concurrentqueue - A fast multi-producer, multi-consumer lock-free concurrent queue for C++11

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](http://moodycamel.com/blog/2014/a-fast-general-purpose-lock-free-queue-for-c++#benchmarks)

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [September 6, 2017, 12:16pm UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/4 "2017-09-06T12:16:54Z")

</div>

This one is a pretty small implementation:

> **[Bounded MPMC queue - 1024cores](http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue)**
>
> All about lockfree, waitfree, obstruction-free synchronization algorithms and data structures, memory models, scalability-oriented architecture, multicore/multiprocessor design patterns, high-performance computing (HPC), multithreading/threading...

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

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [September 25, 2017, 7:07am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/5 "2017-09-25T07:07:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![martinrobinson-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/martinrobinson-2/32/630_2.png) [@martinrobinson-2](https://forum.juce.com/u/martinrobinson-2)\
**Post date:** [September 25, 2017, 7:24am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/6 "2017-09-25T07:24:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![myhrman](https://avatars.discourse-cdn.com/v4/letter/m/a9a28c/32.png) [@myhrman](https://forum.juce.com/u/myhrman)\
**Post date:** [September 25, 2017, 8:08am UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/7 "2017-09-25T08:08:53Z")

</div>

I also wish something like this existed in JUCE

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [September 25, 2017, 2:59pm UTC](https://forum.juce.com/t/feature-request-disruptor-pattern-fifo/23991/8 "2017-09-25T14:59:21Z")

</div>

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!
