I'm learning the JDK9 memory model.
After watching the speech Java Memory Model Unlearning Experience and reading the paper Using JDK 9 Memory Order Modes.
I'm confused about some concepts.
Does opaque immediately guarantee the visibility?
How to understand partial order and total order in the paper?
For the first question, the paper says
It is almost never a good idea to use bare spins waiting for values of variables. Use Thread.onSpinWait, Thread.yield, and/or blocking synchronization to better cope with the fact that "eventually" can be a long time, especially when there are more threads than cores on a system.
So if I write the code:
// shared variable I and VarHandle I_HANDLE which referred to I
public static int I = 0;
public static final VarHandle I_HANDLE;
// Thread-1
I_HANDLE.setOpaque(1);
// Thread-2
while((int) I_HANDLE.getOpaque() == 0){
}
The thread-2 eventually terminate but maybe after a long time?
If so, is there any minimal approach to guarantee thread-2 immediately see the modifying by thread-1? (Release/Acquire?volatile?)