“though there is only one read of the *ps variable in the source code, the compiler is permitted to produce object code that performs multiple reads of the memory.. by the "as-if" principle” As-if you should expect compiled code to do what you asked for https://wiki.sei.cmu.edu/confluence/display/c/CON43-C.+Do+not+allow+data+races+in+multithreaded+code …
Doesn't seem completely unreasonable to me... it's just like how the compiler is also permitted to turn a single store into multiple ones that cause the value to be bogus in between, or how the compiler is allowed to reorder stores, isn't it?
-
-
It’s not unreasonable, I just hadn’t heard of it articulated as the ‘as if principle’, which seems to mean ‘as long as the end result is the same, don’t expect this to do the most obvious thing’. That leads to interesting bugs that are hard to see from looking at source.
-
It’s central to C++’s specification: https://en.cppreference.com/w/cpp/language/as_if …
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.