JavaMemoryModel: Final clarification on volatiles

From: David Holmes (dholmes@dltech.com.au)
Date: Thu May 02 2002 - 22:28:07 EDT


Just confirming. The "happens before" relationship established between
volatile reads and writes only applies to use of the *same* volatile
reference - independent of the object referred to - right? So that the
following:

class Holder {

   volatile int[] store = new int[10];

   Helper helper = new Helper(store);

   // ... methods to read/write store elements
}

class Helper {

   volatile int[] store;

   Helper(int[] theStore) {
       store = theStore
   }

   // ... methods that read store elements
}

does *not* establish any relationship between uses of Holder.store and
Helper.store.

So I'll need to use an inner class to access Holder.store directly.

Thanks,
David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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