I have a direct ByteBuffer (off-heap) in one thread and safely publish it to a different thread using one of the mechanisms given to me by JMM. Does the happens-before relationship extend to the native (off-heap) memory wrapped by the ByteBuffer? If not how can I safely publish the contents of a direct ByteBuffer from one thread to a different one?
Edit
This is not a duplicate of Can multiple threads see writes on a direct mapped ByteBuffer in Java? because
- I am not talking about an mmaped() region but a general off-heap area
- I am safely publishing the ByteBuffer
- I am not concurrently modifying the contents of the ByteBuffer, I am just hading it from one thread to a different one
Edit 2
This is not a duplicate of Options to make Java's ByteBuffer thread safe I am not trying to concurrently modify a ByteBuffer from two different threads. I am trying to hand if over from one thread to a different one and get happens-before semantics on the native memory region backed by a direct ByteBuffer. The first thread will no longer modify or read from the ByteBuffer once it has been handed over.