Hello,
We have the simple pseudocode:
void main(String[] args) {
MemoryBuffer b = new MemoryBuffer(); // it is a off-heap native piece of memory allocated by malloc via JNI
b.init(); // it just write some data to the memory buffer by JNI
startThreadsThatReadsFromBuffer(b); // this functions starts threads that read the b
// There is no locks / synchronization etc.
}
It seems to be thread-safe in the sense of Java Memory Model. But, I cannot convince myself why it is correct. Especially, how can I be sure that worker threads see completely intizalized buffer b?