dispenso 1.6.0
A library for task parallelism
Loading...
Searching...
No Matches
mpmc_ring_buffer.h File Reference
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <new>
#include <type_traits>
#include <utility>
#include <dispenso/platform.h>
#include <dispenso/util.h>

Go to the source code of this file.

Classes

class  dispenso::MpmcRingBuffer< T, Capacity, RoundUpToPowerOfTwo >
 A lock-free multi-producer multi-consumer ring buffer with fixed capacity. More...
 

Detailed Description

A lock-free multi-producer multi-consumer (MPMC) bounded ring buffer.

This buffer implements the Vyukov bounded MPMC queue algorithm, which uses per-slot sequence numbers for synchronization. It provides O(1) fail-fast push and pop operations with no CAS retry loops on the uncontended fast path.

The primary use case is per-thread work queues for fork-join scheduling, where a scheduler pushes targeted work to a specific thread's ring and the thread (or a work-stealing neighbor) pops from it. Bulk push is supported for efficient batch scheduling.

Note
This implementation is thread-safe for multiple producers AND multiple consumers.
See also
docs/design/three_tier_scheduling.md for the design context.
https://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue

Definition in file mpmc_ring_buffer.h.