CppCon 2016 has ended
Wednesday, September 21 • 3:15pm - 4:15pm
Using weakly ordered C++ atomics correctly

Log in to save this to your schedule and see who's attending!

Most programmers should usually avoid C++ atomics altogether and use mutexes instead. If that's not possible, perhaps because the code must be usable in interrupt handlers, I recommend that you consider limiting yourself to sequentially consistent atomics, which provide a more subtle, but still reasonably unsurprising programming model. This talk will target those who choose to ignore both of those pieces of advice, for either good or bad reasons.

I will start by trying to distinguish the good and bad reasons for using weakly ordered atomics, and then follow with guidelines for using them correctly.

I will discuss why it is often incorrect to think of atomics in terms of fence-based implementations, and about some common errors I've seen, including some really convincing looking, but still incorrect, code. I will also try to go through some of the common idioms for which weakly ordered atomics are actually safe. In my experience, the latter are also reasonably common, but not always easy to distinguish from the subtly erroneous examples.

avatar for Hans Boehm

Hans Boehm

Hans is the WG21 SG1 (Concurrency) Chair, and co-led the design of the C++ memory model and atomic operations. He now mostly works on concurrency-related issues in Android, and occasionally on teaching calculators to calculate correctly. In the past, he mostly focused on garbage... Read More →

Wednesday September 21, 2016 3:15pm - 4:15pm
Bowie Hall (1st Floor Hall) Meydenbauer Center

Attendees (183)