RC RANDOM CHAOS

Building a Fast Lock-Free MPMC Queue in Rust With Bounded Waiting

· via Hacker News

Original source

Girls just wanna have fast MPMC queues with bounded waiting

Hacker News →

A developer walks through their design for a bounded, array-based multi-producer/multi-consumer queue built on ticket-lock semantics. The core idea models each slot as a “box” with a display showing whose turn it is: two atomic counters act as ticket dispensers (one for producers, one for consumers), a data ring buffer holds the actual items, and a parallel state ring buffer tracks ownership. Threads take a ticket via fetch-add, spin until their reservation number and type appear on the target slot, perform their read or write, then flip the slot’s status bit to hand it to the opposite role. Because producers and consumers strictly alternate on any given slot, a producer always finds an empty box and a consumer always finds a full one.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.