[concurrency-interest] volatile guarantee for directbuffer

Talip Ozturk oztalip at gmail.com
Tue Feb 14 09:09:54 EST 2012


Say we have thread1 and thread2. Both can access a volatile boolean
variable, 'volatileVar' and DirectByteBuffer instance 'directBuffer'

thread1:
directBuffer.put(myByteArray);
directBuffer.putLong(myLong);
volatileVar = true;

thread2:
if (volatileVar) {
  // read the directBuffer
  directBuffer.get(myByteArray);
  long myLong = directBuffer.getLong();
}

Can I assume that thread2 did read the byte[] and long values?

Does volatile-reads give us happens-before guarantee for OffHeap data?

Thanks,
-talip


More information about the Concurrency-interest mailing list