Re: JavaMemoryModel: Semantics of volatile

From: Bill Pugh (pugh@cs.umd.edu)
Date: Fri Mar 24 2000 - 09:47:46 EST


>
> Initially:
> class X {
> boolean a = false
> volatile Object b = null;
> ...
> }
>
> Thread 1:
> a = true; // not false!
> b = this; // fields of "this" are now visible.
>
> Thread 2:
> while (b == null);
> boolean tmp = a;
>
> Question: Is it possible that thread 2 gets a value of false in tmp?
>

This is essentially another variant of V4. Alternatively, if we wrote it as:

> Initially:
> class X {
> boolean a = false
> volatile Object b = null;
> ...
> }
>
> Thread 1:
> a = true; // not false!
> b = this; // fields of "this" are now visible.
>
> Thread 2:
> X tmp1;
> while ((tmp1 = b) == null);
> boolean tmp2 = tmp1.a;
>
> Question: Is it possible that thread 2 gets a value of false in tmp2?

Then it becomes a variant of V3. The difference between the two is
that in the top example, we are loading a field of the object
referenced by the volatile field, but not through the value loaded
from the volatile field. In the bottom example, we are loading a
through the value loaded from b.
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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