|
|
|
|
|
by vvanders
3956 days ago
|
|
Pretty sure the lack of ordering(memory and execution) semantics for volatile invalidates all of those cases. Really you should be using the appropriate platform memory and execution barriers in place of volatile 99% of the time. |
|
An illustration:
"volatile" is the most precise way to prevent the compiler from hoisting the 'interrupted' access out of the loop. Memory barriers aren't necessary, because the code is single threaded. They may effectively defeat the optimization too, but it's by confusing the compiler instead of informing it.edit: Oh, and std::atomic is a very bad solution to the above. std::atomic may take locks, which can lead to a deadlock if used in a signal handler!