[cpp-threads] Yet another visibility question

Ben Hutchings ben at decadent.org.uk
Sun Dec 10 15:42:56 GMT 2006


On Fri, 2006-12-08 at 19:53 -0600, Boehm, Hans wrote:
<snip>
> 1.10p7:
> {Add synchronizes-with relationships back in for all writer-reader
> pairs of atomic memory operations.  Whether or not something is an
> acquire or release operation no longer affects "synchronizes-with",
> but it still affects "inter-thread-ordered-before" and hence
> "happens-before".  This means that "raw" operations can be used
> to synchronize threads if the "inter-thread-ordered-before"
> relationships are introduced by other ordered operations, which
> now act more like fences, as they generally do on hardware.
> We also provide per-variable TSO, which is what triggered all these
> changes.}
> "An evaluation A that performs a release operation on a location L
> synchronizes-with an evaluation B that performs an acquire operation on
> L and
> reads the value written by A."
> ==>
> "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."

(Is static initialisation counted as a modification?  If not, there
needs to be a special case for that.)

Ben.

-- 
Ben Hutchings
It is easier to write an incorrect program than to understand a correct one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://www.decadentplace.org.uk/pipermail/cpp-threads/attachments/20061210/87a090b7/attachment.pgp


More information about the cpp-threads mailing list