|
From: Patrick J. L. <lop...@gm...> - 2012-12-04 18:32:28
|
On Tue, Dec 4, 2012 at 7:24 AM, Leif Walsh <lei...@gm...> wrote:
>
> I'm ashamed to say I don't quite understand
The first step to enlightenment
> what can fail here but I'm not worried until I start supporting such architectures. Thanks for the warning though.
It is not only about future architectures; it is about smart compilers
on any architecture. Do you ever plan to update your compiler? Then
you should be worried.
It is quite possible for concurrent writes of the _same value_ to
create problems. For a concrete example, see section 2.4 of Hans
Boehm's classic paper:
http://www.usenix.org/event/hotpar11/tech/final_files/Boehm.pdf
The specifics are complicated, but the general idea is very simple. A
data race is "undefined behavior", period. Therefore your compiler
may assume you do not have any and optimize your code accordingly.
(In fact, if your compiler can prove you are engaging in undefined
behavior, it is permitted to compile your entire program into a no-op.
Yes, really.)
Undefined behavior is always a serious bug, precisely because a
trivial, bug-free compiler upgrade can utterly break your program.
Boehm is kind enough to give realistic examples, since bad software
engineers (i.e. most of them) simply refuse to accept this fact
otherwise.
There is no such thing as a benign data race. Ever.
- Pat
|