Fang,
Fang Weijian wrote:
> 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?
Yes.
> However, intuitively, r should equal to 2, e.g. in the JMM in JLS, or in
> release consistency.
This is not true. In terms of the JMM in the JLS, a write corresponding
with (1) can intervene between the write corresponding with (6) and the
read corresponding with (3).
> 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.
The new JMM is no different from the old one in this respect.
Regards
Bart
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:53 EDT