Building Robust Inter-Process Queues in C++

Jody Hagins

⏱ 75 mins
intermediate
advanced
11:00-12:15, Monday, 23rd June 2025

The C++ standard was written with a single-process worldview. Processes are mentioned once - in a note stating that lock-free atomic operations work across process boundaries. This single note has led to widespread but incorrect advice across Stack Overflow and blogs about using std::atomic in shared memory. The reality is far more complex.

Moving queue implementations from threads to processes reveals a cascade of subtle failures. Traditional queue designs that work perfectly for thread communication break surprisingly when crossing process boundaries.

Two popular open-source SPSC C++ implementations (Daugaard and Rigtorp) will be examined to determine the required changes to use those queues in inter-process shared memory. We will then consider the interface for these queues in light of using them across process boundaries, which will reveal that the traditional intra-process queue API is inadequate for inter-process usage. We will consider an alternative inter-process queue design separating the interface into three components.

This code-heavy presentation will tackle complex problems, such as maintaining implicit lifetime properties while restricting dangerous operations, handling process death during critical sections, and enforcing type constraints that differ between copy and direct-access strategies.

Then, we'll push further into MCAST queues, where each consumer sees every message, forcing us to deal with increased complexity around message delivery guarantees and slow reader handling.

Throughout, we'll see how each solution reveals new challenges, leading us to build a comprehensive approach to shared memory queues that works not just in theory but in the unforgiving world of production systems where processes die, readers stall, and our standard tools don't always behave as expected.

Jody Hagins

Jody Hagins has been using C++ for the better part of four decades. He remains amazed at how much he does not know after all those years. He has spent most of that time designing and building systems in C++, for use in the high frequency trading space.