On 03/24/11 14:58, Richard Henderson wrote:
On 03/24/2011 10:33 AM, Aldy Hernandez wrote:
In the example below we usually hoist "global" into a register or
temporary to avoid reading from it at each step. This would cause a
race if another thread had modified "global" in between iterations.
for (x=0; x< 5; x++)
sum[x] = global;
Um, what? Doesn't the c++ memory model have, like, sequence points
or somesuch verbage that includes some language like an "atomic"?
Your argument above, in absence of some serializing entity, does not
sound right at all.
This work is independent of the C++ memory model. It is just to prevent
the optimizers from introducing new data races due to code movement.
This initial pass is just to make the optimizations data race safe so
that if you have a program which is proven to be free of data races, you
can run the optimizers and it will still be data race free after the
optimizers have been run.
See the following summary by Andrew (which in turn is based on a paper
by Hans Boehm):
http://gcc.gnu.org/wiki/Atomic/GCCMM/DataRaces
The code movement is disallowed under specific --param options and will
later be used for the C++ memory model, though the kernel folk have been
asking for something similar, so it's not C++ specific.
Does this make sense now? Or were Andrew and I smoking some heavy duty
stuff when reading the specs... and not sharing with you?
Aldy