Back To Schedule
Tuesday, November 15 • 10:00am - 10:50am
Thread synchronisation in real-time audio processing with RCU (Read-Copy-Update)

Log in to save this to your schedule, view media, leave feedback and see who's attending!

When developing real-time audio processing applications in C++, the following problem arises almost inevitably: how can we share data between the real-time audio thread and the other threads (such as a GUI thread) in a way that is real-time safe? How can we synchronise reads and writes to C++ objects across threads, and manage the lifetime of these objects, while remaining wait-free on the real-time thread?

In certain cases, we can store the objects inside a std::atomic or use techniques such as lock-free FIFOs, spinlocks, and double buffering. However, typically in the generic case of reading the value of a sufficiently large, persistent object on the real-time thread that is simultaneously mutated on another thread, none of these are applicable. What do we do then? How do we avoid memory leaks while ensuring that the real-time audio thread won't end up blocking, performing deallocations, or reading an object that has already been deleted from under it?

One possibility is to use atomic_shared_ptr, but correct and lock-free implementations are hard to come by. And even if you have such an implementation, this approach typically suffers from slow performance, has poor portability across platforms, and introduces even more complexity. Is there an alternative solution?

If we look beyond the audio industry, it turns out there is actually another strategy that solves this problem quite elegantly: RCU (Read-Copy-Update). RCU has been successfully used in the Linux kernel for two decades. More recently, it has been adapted for user space applications as well. There is even a proposal to add RCU to the C++ standard library.

In this talk, we take a detailed look at the RCU (Read-Copy-Update) mechanism. We discuss how it works, what the tradeoffs and design choices are, and how to adapt the algorithm for a real-time audio context.


avatar for Timur Doumler

Timur Doumler

Independent, Independent
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... Read More →

Tuesday November 15, 2022 10:00am - 10:50am GMT
2) AltTab 10 South Pl, London EC2M 7EB, UK