Stay up-to-date with everything C++!
Content directly fetched from the subreddit just for you.
Join our group for discussions : @programminginc
Powered by : @r_channels
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
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