Re: JavaMemoryModel: Volatile array references

From: Bill Pugh (
Date: Tue Apr 30 2002 - 23:09:59 EDT

At 12:51 PM +1000 5/1/02, David Holmes wrote:
>In the proposed model does the strengthening of volatile give the effect of
>having volatile array elements when accessed via a volatile array reference?

Unfortunately, there is no way in the Java type system to have the
elements of an array be volatile. You can have a volatile field that
contains a reference to an array, but that isn't the same thing.

If you want to get the effect of an array with volatile elements,
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).

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:39 EDT