RE: JavaMemoryModel: a naive proposal

From: Boehm, Hans (hans_boehm@hp.com)
Date: Thu Jul 12 2001 - 14:09:45 EDT


[This is really an expansion on the last point from my previous message.]

> From: Bill Pugh [mailto:pugh@cs.umd.edu]

...
> If you want, you could write your own Java source code to Java byte
> code compiler that inserted a dummy volatile write followed by a
> dummy volatile read after each memory access. That would provide SC
> semantics. But those semantics won't be the semantics of Java.

If I understand everything correctly, You would also need to at least make
all original variables volatile. Consider four threads (2 mutators + two
observers) executing, with shared variables x = 0 and y = 0 initially. (I
use <barrier> to denote a dummy volatile read and write.)

Mutators:

Thread 1:
<barrier>
x = 1;
<barrier>

Thread 2:
<barrier>
y = 1;
<barrier>

Observers:

Thread 3:
<barrier>
read x;
<barrier>
read y;
<barrier>

Thread 4:
<barrier>
read y;
<barrier>
read x;
<barrier>

Can thread 3 see x = 1 and y = 0 (x is written first), while thread 4 sees y
= 1 and x = 0 (y is written first)? I think the answer is yes, unless we
require there to be a total ordering on all writes, not just volatile ones.

If you reinterpret this example as an attempt to implement actions on
volatile variables x and y, it also explains why I think it may be hard to
enforce a total ordering on volatile writes, even if the hardware provides
memory barriers.

Hans

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



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