[concurrency-interest] Assignment of references atomic?

Jeremy Manson jmanson at cs.purdue.edu
Wed Oct 12 19:23:28 EDT 2005

The word synchronize is slightly overloaded here, and I think it could 
use some more explanation for those unfamiliar with its use.

One meaning involves any mechanism that can be used to communicate 
between threads: locking, volatiles, atomics, final fields, etc.  These 
things all constitute synchronization actions.

If you want to communicate between threads, you need to use 
synchronization actions, whether they be locking, volatiles, or anything 
else.  This is what Brian was describing.

Another meaning is the language construct used for built-in locking, the 
synchronized block.  A synchronized block implies two synchronization 
actions: a lock action and an unlock action.

If you want to ensure mutual exclusion, you need to use locks, and may 
use a synchronized block to do so.

For this example, it is definitely necessary to use some synchronization 
action.  Depending on the desired semantics, it may or may not be 
necessary to use locking (in the form of a synchronized block or a 
JSR-166 lock).


David Holmes wrote:
>>Chris Purcell writes:
>>Just to clarify here: you can synchronize by using the "volatile"
>>keyword, right? You do not need to use the "synchronized" keyword?
> You can use the volatile keyword to ensure that things are visible and that
> the right ordering is maintained.
> For example, this is perfectly safe:
>   volatile boolean dataReady = false;
>   Object theObject;
>   Thread-1                             Thread-2..n
>   theObject = makeObject();            if (dataReady)
>   dataReady = true;                        use(theObject);
> Here there is a single writer and many potential readers. As long as the
> readers see dataReady is true then they are guaranteed to see everything
> that happened to theObject during makeObject().
> But volatile in itself is not sufficient *if* there is a need for atomicity
> between deciding to update the object and performing the update.
> David Holmes
> _______________________________________________
> 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