[concurrency-interest] Synchronization question

Dhanji R. Prasanna dhanji at gmail.com
Wed Jun 28 08:14:55 EDT 2006

On 6/28/06, Holger Hoffstätte <holger at wizards.de> wrote:
> Brian Goetz wrote:
> > And, just for completeness: synchronized write + nonsynchronized read
> > doesn't create the required happens-before, so it doesn't work.  The
> > getter in such a case isn't required to ever return anything other than
> > the default (zero) value.
> This made me curious. While "strictly speaking" the above behaviour might
> be correct according to the spec/revised memory model, in practice (as in
> stuff I can buy/run today) the unsynchronized read *will* succeed - maybe

I believe with regard to the original question, the unsynchronized
read is not expected to be deterministic because there isnt a
happens-before edge forcing the 2 threads into a write/read sequence.
Im not sure what you mean by "succeed", but for the required behavior
(i.e. write prior to read) one cannot guarantee that a synchronized
write + unsynchronized read will suffice.

Declaring the variable as volatile forces both threads to deal with
the same memory but still does not solve the issue of sequencing the
write/read. This is how I read Brian's and the others' responses.

More information about the Concurrency-interest mailing list