TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24301 22
Simple MPSCQueue with explanation

My previous post got deleted because It seems like AI detector has disliked the "polished" style of the post. I guess it should be rewritten in a more "casual" way, with grammar errors. Sorry for duplication if anyone has seen this already.

\----
During my free time, I have stumbled upon such segment of C++ as "low latency" and "lock free". This topic has initially fascinated me so much, because I couldn't have even imagined that some thing like this could even exist, and is actively used in a very interesting and specific segment of the market... But that is a story for another time :)

I have decided to get familiar with the topic, and as my first step, I wanted to implement something. I have chosen MPSC (Multiple Producer, Single Consumer) queue, but I've quickly realised that the entry barrier is overly high. I literally had no understanding of where I could start.

I spent several weeks gathering knowledge bit by bit, studying advanced multithreading, atomics, memory ordering, and lock-free algorithms. Finally I came up with something I want to share here.

I thought it would be valuable to create a detailed walkthrough, which can be used either by me in future, when I get back to this in maybe several month or years, my friends who would love to learn about this topic, or anyone else who would find themselves in a situation like this.

This project is for sure not the best, not ideal, and not something universe-changing. It is just a "school-grader-level" project with the explanation, hopefully understandable to the same "school-grader".

I, personally, would have loved to have an article like this while I was learning, since it could save at least several weeks, so I hope it helps others in the same way.

https://github.com/bowtoyourlord/MPSCQueue

Any critics welcome.

https://redd.it/1p2bizu
@r_cpp
GitHub GitHub - bowtoyourlord/MPSCQueue: A simple, lock-free MPSC (Multiple Producer, Single Consumer) queue implemented in C++ for learning… A simple, lock-free MPSC (Multiple Producer, Single Consumer) queue implemented in C++ for learning and experimentation purposes. Useful for everyone who is interested in low latency & extr...
More from @r_cpp
  1. Oct 12, 2026ACCU Overload Journal 195 - October 2026 https://accu.org/journals/overload/overload195 ht…
  2. Oct 12, 2026C++ Contracts C++ contracts are a good thing, why are people saying it's a bad thing? Anyb…
  3. Oct 11, 2026wxWidgets 3.2.12 and 3.3.4 Released https://wxwidgets.org/news/2026/10/wxwidgets-3.2.12-an…
  4. Oct 11, 2026VKRT NES Remaster — an open-source C++20 NES emulator with an observation-driven remasteri…
  5. Oct 11, 2026Right way to test async code https://redd.it/1x2wqgz @r_cpp
  6. Oct 10, 2026Yantra: an LALR(1) parser generator for C++23 Yantra: an LALR(1) parser generator for C++2…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →