Re: JavaMemoryModel: Moving memory operations across external actions

From: Sylvia Else (sylviae@optushome.com.au)
Date: Thu Apr 15 2004 - 13:54:20 EDT


At 01:04 PM 15/04/2004 -0400, Bill Pugh wrote:
>OK, here is a better, more concrete example.
>
>
>Initially, x = 0
>
>Thread 1:
>r1 = readSocket1()
>x = 1
>
>Thread 2:
>r2 = x
>writeSocket2(r2)
>
>Note: readSocket1() will always return 0, unless
>there is an earlier write of 1 to socket 2. Because these
>are different sockets, their implementation might not
>synchronize on any object in common.
>
>Behavior in question: r1 == r2 == 1

Does this really differ in essence from

y not volatile, initially zero.
Thread 1:

r1 = (y == 1) ? 1 : 0;
x = 1

Thread 2

r2 = x
y = r2

Behavior in question: r1 == r2 == 1

A prescient write of x gives the behaviour in question. The external world
behaves like non-volatile memory for the purposes of the memory model, and
the example contains a data-race.

Sylvia.

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:04 EDT