Skip to content

add MPMC queue (Vyukov design)#2

Open
AneesPatel wants to merge 1 commit into
mainfrom
feat/mpmc-queue
Open

add MPMC queue (Vyukov design)#2
AneesPatel wants to merge 1 commit into
mainfrom
feat/mpmc-queue

Conversation

@AneesPatel

Copy link
Copy Markdown
Owner

What

MPMC ring buffer using per-slot sequence counters. Based on Dmitry Vyukov's classic design - each slot coordinates its own producer/consumer handoff instead of a single shared lock.

Why this vs the existing SPSC buffer

The existing LockFreeRingBuffer only works with one producer and one consumer. This one handles arbitrary N producers and M consumers safely. The tradeoff is slightly more overhead per operation (one extra atomic load per slot).

Notes

  • Head/tail live on separate cache lines (alignas(64)) to avoid false sharing - worth it when multiple threads hammer both ends.
  • Capacity must be a power of two.
  • Push/pop are non-blocking and return false/nullopt if full/empty.
  • Stress tested: 4 producers x 4 consumers, 1M items, verify the sum matches.

Files

  • include/MPMCQueue.h
  • tests/test_mpmcqueue.cpp
  • CMakeLists.txt

Per-slot sequence counters for coordination — no single shared lock.
Head/tail on separate cache lines to avoid false sharing between
producers and consumers. Stress tested with 4+4 threads, 1M items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant