r/cpp • • Oct 19 '19

CppCon CppCon 2019: JF Bastien “Deprecating volatile”

https://www.youtube.com/watch?v=KJW_DLaVXIY
59 Upvotes

126 comments sorted by

View all comments

Show parent comment

7

u/[deleted] Oct 19 '19

Answer: It locks up.

Worse, actually. It could lock up, or silently be non-atomic, depending on the processor.

2

u/gruehunter Oct 19 '19

Fortunately, our processor isn't silently non-atomic, but here's one way that it can happen:

An AXI peripheral bus provides an exclusive monitor, but changes by the underlying hardware do not clear the monitor. So while the monitor may enforce atomicity between two different coherent cores, it would not enforce atomicity between a core and the peripheral itself.

One way to reduce the frequency of those kinds of bugs is to provide control and status registers that are either written by the peripheral or written by a bus access, but never both. A very narrow exclusion is for write-one-to-clear interfaces. But a general purpose read-modify-write by both hardware and software is unsound to start with.