RE: JavaMemoryModel: a naive proposal

From: Boehm, Hans (
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 []

> 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.)


Thread 1:
x = 1;

Thread 2:
y = 1;


Thread 3:
read x;
read y;

Thread 4:
read y;
read x;

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.


JavaMemoryModel mailing list -

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