The following excerpt is taken from the website https://lwn.net/Articles/262464/ and it is dealing with read-inconsistencies of shared data structures (for which there was the RCU created):
p = gp; if (p != NULL) { do_something_with(p->a, p->b, p->c); }
Although this code fragment might well seem immune to misordering, unfortunately, the DEC Alpha CPU [PDF] and value-speculation compiler optimizations can, believe it or not, cause the values of p->a, p->b, and p->c to be fetched before the value of p! This is perhaps easiest to see in the case of value-speculation compiler optimizations, where the compiler guesses the value of p, fetches p->a, p->b, and p->c, then fetches the actual value of p in order to check whether its guess was correct. This sort of optimization is quite aggressive, perhaps insanely so, but does actually occur in the context of profile-driven optimization.
It is unclear to me whether the above code is meant to produce erroneous (*) values in the access to p->a
etc. which scares the sh.t out of me, or if it is meant as "other CPUs can observe the fetches in another than the written (in source) order" which would be totally,unsurprisingly ok to me.
If the first interpretation is correct I consider systems (compilers) which allow this kind of behaviour broken. My question is if this thing still exists, even when the prevalent architecture (Alpha) already may have vanished.
(*) Erroneous values in the sense of p->a
being from one record and p->b
from another or something worse
PS: I didn't check but I assume the gp
variable to be correctly decorated with atomic
or the like.