[concurrency-interest] a question about concurrent safe access

Peter Veentjer - Anchor Men p.veentjer at anchormen.nl
Tue Sep 20 03:19:56 EDT 2005


 
But what can happen if a field is used in a multithreaded environment
and it isn`t synchronized or volatile. Could you get some serious
vm-errors (or totally unacceptable behaviour of the program)? Or just an
old reference?

-----Oorspronkelijk bericht-----
Van: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu] Namens David Holmes
Verzonden: dinsdag 20 september 2005 1:31
Aan: Stefan Skoglund
CC: concurrency-interest at altair.cs.oswego.edu
Onderwerp: RE: [concurrency-interest] a question about concurrent safe
access

Stefan,

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
does:

  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.

David Holmes


> -----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.
>
> yours
> /Stefan
>
>
> 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
> >http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
> >
> >
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest at altair.cs.oswego.edu
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest




More information about the Concurrency-interest mailing list