[cpp-threads] Yet another visibility question
Boehm, Hans
hans.boehm at hp.com
Tue Dec 12 01:37:46 GMT 2006
> From: Ben Hutchings
> > ==>
> > "All modifications to a particular memory location L occur in some
> > particular total order, referred to as the modification order for L.
> > An evaluation A that performs a synchronization operation that
> > modifies location L synchronizes-with an evaluation B that
> reads the
> > value written by A, or reads a value that was subsequently (in
> > modification
> > order) written to L.
> <snip>
>
> This wrongly matches each write with *every* read of the same
> value, when what I think we want is to match each read with a
> single write of the same value. Example:
>
> Atomic variables x, y initialised to 0
> Thread 1: x = 1;
> x = 0;
> y = 1;
> x = 1;
> Thread 2: while (!x);
> assert(y);
>
> By my reading of the new wording, the second assignment of 1
> to x in thread 1 must synchronise with the evaluation of x in
> thread 2 that reads 1, so that the assertion succeeds.
> Really we expect that thread 2 might synchronise only with
> the first assignment of 1 to x in thread 1, so that the
> assertion can fail.
>
> I would like to suggest the following wording:
>
> "All modifications to a particular memory location L occur in
> some particular total order, referred to as the modification
> order for L. For any evaluation B that reads the value of L,
> there is some modification A such that A writes the value
> read by B and A and each modification of L that occurs
> earlier in the modification order synchronizes-with B."
We certainly agree on the intent, and on the fact that I didn't state it
well. Your restatement is better, but maybe still a little hard to
parse. Maybe Clark can do better still?
>
> (Is static initialisation counted as a modification? If not,
> there needs to be a special case for that.)
That's also a good point. I think that's currently less clear than it
should be.
Hans
>
> Ben.
>
> --
> Ben Hutchings
> It is easier to write an incorrect program than to understand
> a correct one.
>
More information about the cpp-threads
mailing list