Java Memory Model mailing list archive: Re: JavaMemoryModel: an (original) (raw)
Re: JavaMemoryModel: another question on volatile
From: Bill Pugh (pugh@cs.umd.edu)
Date: Wed Mar 17 2004 - 21:24:04 EST
- Next message: Bill Pugh: "Re: JavaMemoryModel: Minor issue on hb edges and interrupts"
- Previous message: David Holmes: "RE: JavaMemoryModel: another question on volatile"
- In reply to: Thomas Wang: "JavaMemoryModel: another question on volatile"
- Next in thread: Vijay Saraswat: "Re: JavaMemoryModel: another question on volatile"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Mail actions: [ respond to this message ] [ mail a new topic ]
On Mar 17, 2004, at 7:39 PM, Thomas Wang wrote:
> Initially, x = y = v = 0. v is a volatile variable.
>
> Thread 1:
> r1 = x
> v = 0
> y = 1
>
> Thread 2:
> r3 = y
> v = 0
> x = 1
>
> Is the behavior r1 == r3 == 1 possible?
>
Yes (under both weak and strong interpretations)
As David noted, a write to a volatile serves as a release, and
"publishes" the memory accesses
that occur before it to anyone who later reads that volatile (with
slight differences for the strong/weak
interpretation).
For example, compilers can reorder a volatile write and a following
non-volatile memory access, resulting in:
thread 1:
y = 1
r1 = x
v = 0
thread 2:
x = 1
r3 = y
v = 0
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
- Next message: Bill Pugh: "Re: JavaMemoryModel: Minor issue on hb edges and interrupts"
- Previous message: David Holmes: "RE: JavaMemoryModel: another question on volatile"
- In reply to: Thomas Wang: "JavaMemoryModel: another question on volatile"
- Next in thread: Vijay Saraswat: "Re: JavaMemoryModel: another question on volatile"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Mail actions: [ respond to this message ] [ mail a new topic ]
This archive was generated by hypermail 2b29: Thu Oct 13 2005 - 07:01:00 EDT