JavaMemoryModel: An incorrectly synchronized case

From: Fang Weijian (
Date: Thu Nov 13 2003 - 04:52:22 EST

Consider this case:

Initially, x=0

Thread 1:
(1) x=1;
(2) lock
(3) r=x;
(4) unlock;

Thread 2:
(5) lock
(6) x=2;
(7) unlock;

All the lock/unlock are performed on the same monitor. We assume (2) lock in
thread 1 is a subsequent action with respect to (7) unlock in thread 2,
i.e. (7) HB (2)

Then in (3) r=x in thread 1, both r = 1 and r =2 are valid according to the
proposed JMM. There are two coexistent happens-before relationship that a
write HB a read and there is no other write intervening: (1) HB (3), and (6)
HB (3). Am I correct?

However, intuitively, r should equal to 2, e.g. in the JMM in JLS, or in
release consistency. Since we can not guarantee our program must be
correctly synchronized (can we?), sometimes we may need to reason on the
unintentional incorrectly synchronized program. While at that situation, the
proposed JMM might be against our intuition.



JavaMemoryModel mailing list -

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