[concurrency-interest] Synchronization question

Jeremy Manson jmanson at cs.purdue.edu
Tue Jun 27 17:01:51 EDT 2006


Hi Ryan,

There has to be a happens-before relationship between the assignment to 
the variable and any read of it.  This means that, when you say:

> The system is written such that these other threads will NOT invoke the
> non-synchronized accessor method until the synchronized method is
> invoked.

Then if there is a happens-before relationship making this guarantee, 
then you are fine.

The happens-before guarantee can be made by, for example, a write to a 
volatile in the writer thread after the write, and a read of the same 
variable in the reader thread before the read. Alternatively, you can 
have an unlock in the writer thread after the write, followed by a lock 
on the same monitor in a reader thread before the read.  Alternatively, 
you can have the writer thread start the reader threads after it 
performs the write.

					Jeremy


More information about the Concurrency-interest mailing list