[concurrency-interest] Volatile array and Wait

Jeremy Manson jmanson at cs.purdue.edu
Wed Oct 19 10:39:59 EDT 2005


Inanc Gumus wrote:
> So, how to make inter array elements volatile?
> 

There is no way to do this directly.  The simplest option is probably to 
use AtomicReferenceArray, AtomicIntegerArray or AtomicLongArray.

Another option is to have an extra volatile dummy field associated with 
the array.  After each write to an array element, write to the dummy 
field (it doesn't matter what value is written).  Before each read of an 
array element, read the dummy field (and discard the value).

A third option is to use indirection.  That is to say, you could create 
an array of references to:

      class VolatileRef {
        public volatile Object ref = null;
     }


A fourth option is to use locking instead.

					Jeremy


More information about the Concurrency-interest mailing list