[concurrency-interest] a question about concurrent safe access
dholmes at dltech.com.au
Mon Sep 19 19:31:09 EDT 2005
As of Java 5 the new Java Memory Model gives very precise semantics to
volatile and you are indeed guaranteed certain behaviour - it is not an
artefact of an implementation.
The JMM guarantees that a write of a volatile variable happens-before a read
of that variable that sees the written value. This means that if Thread-X
Global.R = new B();
and Thread-Y reads Gobal.R and finds the reference to the B object, then it
is guaranteed to see everything that occurred in Thread-X prior to the
assignment to Global.R ie all the construction actions.
> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of
> Stefan Skoglund
> Sent: Monday, 19 September 2005 9:37 PM
> To: Yechiel Feffer
> Cc: concurrency-interest at altair.cs.oswego.edu
> Subject: Re: [concurrency-interest] a question about concurrent
> safe access
> Theoretically, I guess you could get a dirty reference if you used a
> volatile reference. Consider the two treads X and Y. And consider
> volatile reference R pointing to A, seen by both threads. If X creates
> object B and lets R point to B, then Y would see reference R point to
> where B should reside. But since no memory synchronization is guarantied
> to have occurred. except the volatile reference. it would be possible
> that Y sees a dirty reference.
> However as I understand, the current implementation of volatile reads
> and writes, does perform full blown memory synchronization between two
> threads, exchanging information through a volatile reference. So the
> dirty reference would never appear. I'm not sure one should rely the
> fullblown memory synchronization though.
> I guess one of the experts could verify this.
> Yechiel Feffer wrote:
> > Hi all
> > say I have a pointer ( reference) to an object ( A). This reference is
> > changed to point at object B. I have threads that concurrently are
> > using that reference to get the object it points at. I dont want to
> > synchronize the usage of the reference. Is it safe to do so, i.e. if I
> > dont use a lock and I dont declare the reference volatile will I
> > always get object A or B or do I have a risk of getting "dirty"
> > inconsistent pointer , i.e. is assigning a pointer always atomic ?
> > Regrds,
> > Yechiel
> >Concurrency-interest mailing list
> >Concurrency-interest at altair.cs.oswego.edu
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
More information about the Concurrency-interest