CppCon 2016: Hans Boehm “Using weakly ordered C++ atomics correctly'

preview_player
Показать описание


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.

Hans Boehm
Google


*-----*
*-----*
Рекомендации по теме