<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct" -->

---
title: Girls Just Wanna Have Fast MPMC Queues with bounded...
description: A deep dive into designing and implementing a bounded multi-producer multi-consumer (MPMC) queue in Rust using a ticket-lock-based wait system. The design...
canonical: https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Girls Just Wanna Have Fast MPMC Queues with bounded waiting · Nahla | daily.dev
og:description: A deep dive into designing and implementing a bounded multi-producer multi-consumer (MPMC) queue in Rust using a ticket-lock-based wait system. The design...
og:url: https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct
og:image: https://api.daily.dev/og/posts/gzJbL7McT.png
og:image:alt: Girls Just Wanna Have Fast MPMC Queues with bounded waiting · Nahla
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Girls Just Wanna Have Fast MPMC Queues with bounded waiting · Nahla

**[Hacker News](https://daily.dev/sources/hn)** · 15 min read · 6 upvotes · 0 comments

## Summary

A deep dive into designing and implementing a bounded multi-producer multi-consumer (MPMC) queue in Rust using a ticket-lock-based wait system. The design avoids CAS loops by using two atomic counters (producer and consumer) alongside a ring buffer and a state buffer that tracks ownership via a bitfield. Key advantages include bounded waiting, minimized head-of-line blocking, and low cache contention. The post includes a correction noting the structure is not truly wait-free (OS thread suspension can block other threads), detailed benchmark results across various producer/consumer ratios on a Ryzen 7 7800X3D, and discussion of edge cases like integer overflow and costly drivable operation drops.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://nahla.dev/blog/waitfree_queue>

## Questions this post answers

### What is the difference between a wait-free queue and a queue with bounded waiting?

A wait-free structure guarantees that the failure or suspension of one thread cannot cause failure or suspension of another thread, while bounded waiting only guarantees an upper time bound on operations assuming all participating threads remain active. A ticket-based MPMC queue design can offer bounded waiting but not true wait-freedom if a stalled consumer or producer can block others waiting on the same slot indefinitely.

_daily.dev surfaces write-ups like this for developers reasoning precisely about lock-free versus wait-free guarantees._

### How can a fixed-size ring buffer queue avoid CAS loops while supporting multiple producers and consumers?

By using a ticket-lock style design with two atomic counters (one for producers, one for consumers) and a separate state buffer that tracks whose turn it is for each slot via a reservation number and a status bit. Producers and consumers spin-read the state buffer entry rather than performing compare-and-swap retries, keeping the cache line in a shared MESI state and reducing contention.

_developers optimizing concurrent queues can track designs like this through daily.dev before implementing their own._

### Why can dropping a 'drivable' queue operation early cause a deadlock?

Once a producer or consumer increments its reservation counter, it commits to fully completing that operation because the state buffer slot only advances when the operation finishes. If a drivable operation struct is dropped before completion, its drop implementation must drive the operation to completion anyway, or the slot becomes permanently stuck, blocking every subsequent operation that lands on it.

_daily.dev helps engineers debugging queue deadlocks compare edge cases like this drivable-operation gotcha._

## Similar posts on daily.dev

- [Building a Fast Lock-Free Queue in Modern C\+\+ From Scratch](https://daily.dev/posts/building-a-fast-lock-free-queue-in-modern-c-from-scratch-zjxr2g4ab) · Hacker News · 1 upvotes · 0 comments
- [Concurrent Servers: Part 7](https://daily.dev/posts/concurrent-servers-part-7-p5cowxjcu) · Eli Bendersky · 4 upvotes · 0 comments
- [Introducing ractor\_queue: A Shared Queue for Ruby Ractors](https://daily.dev/posts/introducing-ractor-queue-a-shared-queue-for-ruby-ractors-dfc4j5aoy) · Ruby Flow · 0 upvotes · 0 comments
- [Concurrent, atomic MSI hash tables](https://daily.dev/posts/concurrent-atomic-msi-hash-tables-qocsq28mz) · null program · 0 upvotes · 0 comments

---

Tags: [#rust](https://daily.dev/tags/rust)

[View this post on daily.dev](https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Girls Just Wanna Have Fast MPMC Queues with bounded waiting · Nahla","url":"https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct"},"datePublished":"2026-07-09T19:39:39.493Z","dateModified":"2026-09-14T07:37:05.891Z","description":"A deep dive into designing and implementing a bounded multi-producer multi-consumer (MPMC) queue in Rust using a ticket-lock-based wait system. The design...","image":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","thumbnailUrl":"https://media.daily.dev/image/upload/s--foaA6JGU--/f_auto/v1722860399/public/Placeholder%2004","isAccessibleForFree":true,"articleSection":"Hacker News","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Hacker News","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/hn","url":"https://daily.dev/sources/hn"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hacker News","item":"https://daily.dev/sources/hn"},{"@type":"ListItem","position":3,"name":"Girls Just Wanna Have Fast MPMC Queues with bounded waiting · Nahla"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/girls-just-wanna-have-fast-mpmc-queues-with-bounded-waiting-nahla-gzjbl7mct#faq","mainEntity":[{"@type":"Question","name":"What is the difference between a wait-free queue and a queue with bounded waiting?","acceptedAnswer":{"@type":"Answer","text":"A wait-free structure guarantees that the failure or suspension of one thread cannot cause failure or suspension of another thread, while bounded waiting only guarantees an upper time bound on operations assuming all participating threads remain active. A ticket-based MPMC queue design can offer bounded waiting but not true wait-freedom if a stalled consumer or producer can block others waiting on the same slot indefinitely. daily.dev surfaces write-ups like this for developers reasoning precisely about lock-free versus wait-free guarantees."}},{"@type":"Question","name":"How can a fixed-size ring buffer queue avoid CAS loops while supporting multiple producers and consumers?","acceptedAnswer":{"@type":"Answer","text":"By using a ticket-lock style design with two atomic counters (one for producers, one for consumers) and a separate state buffer that tracks whose turn it is for each slot via a reservation number and a status bit. Producers and consumers spin-read the state buffer entry rather than performing compare-and-swap retries, keeping the cache line in a shared MESI state and reducing contention. developers optimizing concurrent queues can track designs like this through daily.dev before implementing their own."}},{"@type":"Question","name":"Why can dropping a 'drivable' queue operation early cause a deadlock?","acceptedAnswer":{"@type":"Answer","text":"Once a producer or consumer increments its reservation counter, it commits to fully completing that operation because the state buffer slot only advances when the operation finishes. If a drivable operation struct is dropped before completion, its drop implementation must drive the operation to completion anyway, or the slot becomes permanently stuck, blocking every subsequent operation that lands on it. daily.dev helps engineers debugging queue deadlocks compare edge cases like this drivable-operation gotcha."}}]}
```

