[concurrency-interest] concurrency puzzle

David Holmes dcholmes at optusnet.com.au
Sun Sep 10 20:40:00 EDT 2006


Jeremy Manson wrote:
> Having said that, the fact that print() can't write out 0 has nothing to
> do with the constructing thread.  Basically, there is a conceptual write
> of 0 to x that happens-before every other action in the program, at "The
> Dawn of Time" (this corresponds to the GC zeroing out memory).  Your
> program can be abstracted in the following way:
>
> "The Dawn of Time":
> // zeroes out all memory, including:
> f.x = 0;
>
> Thread 1:
> // The dawn of time happens-before this:
> f.x = 10;
> global.a = f;
>
> Thread 2:
> // The dawn of time happens-before this:
> g = global.a;
> g.x = 20;
> print(g.x);
>
> The execution engine for Thread 2 will know that the write of 20 has
> overwritten the write of 0, because it knows that the write of 0
> occurred at the dawn of time.  It won't print 0.

So this means that:

   class A {
       int x;
       ...
   }

is semantically different to:

   class A {
       int x = 0;
       ...
   }

because the explicit write of zero to x could "appear" later (even though it
is overwriting a zero value in main memory) just as the value 10 could
"appear" later.

Wow! That is a very subtle distinction. I'm not sure there are any practical
consequences arising from it but I find it disconcerting to have this
difference.

Cheers,
David Holmes



More information about the Concurrency-interest mailing list