Understanding Vyukov MPMC ring buffer
Intro
Recently I had to create a simple MPMC ring buffer for inter-cpu communication based on shared memory between them. For simplicity let’s imagine N threads, which share same buffer and exchange messages of the fixed size. Quick search in known concurrency-related blogs showed me very simple ring buffer by Dmitry Vyukov.
In this blog post I will summarize how it works.
Bounded MPMC Queue
MPMC stands for multi-producer and multi-consumer queue, which means that queue support multiply concurrent readers and writers while reversing consistency. Bounded means that queue can hold only fixed number of messages. If queue is full, then push will fail.