Back To Schedule

Demystifying std::memory_order

00:00 - 00:00 | Friday 31st October 2025 |
Advanced

Atomic variables are an important tool for low-latency and real-time audio processing as they are essential to implementing any kind of lock-free algorithm or data structure. In C++, atomic variables are readily available in the Standard Library through std::atomic. However, in order to use std::atomic not only correctly, but also efficiently and performantly, it is crucial to pick the correct memory order for the atomic operation at hand depending on the requirements of the algorithm. This can be accomplished via the std::memory_order parameter that every atomic operation in C++ accepts. Yet memory order in C++ is notoriously hard to reason about and often misunderstood.

In this talk, we give a brief overview over the C++ memory model, why it is needed, and how it maps to what happens in actual hardware. We explain the differences between relaxed, consume, acquire, release, and sequentially consistent memory order, and give practical guidelines for which to use when for working with atomic reads, writes, read-modify-write operations, and memory fences.

Timur Doumler

Timur Doumler is the co-host of CppCast and an active member of the ISO C++ standard committee, where he is currently co-chair of SG21, the Contracts study group. Timur started his journey into C++ in computational astrophysics, where he was working on cosmological simulations. He then moved into the audio and music technology industry, where he has spent over a decade of his career, worked on projects such as NI Kontakt and the JUCE framework, and co-founded the music tech startup Cradle. In the past, Timur also worked for JetBrains, first as a developer on CLion's C++ parser and later as a Developer Advocate for C++ developer tools. Currently, Timur lives in Finland, where he organises the monthly C++ Helsinki meetup and works as an independent C++ consultant. Timur is passionate about clean code, good tools, low latency, and the evolution of the C++ language.

VolumetricCondensed