Consider a snippet taken from Joshua Bloch’s Java Concurrency book -
public class NoVisibility{
private static boolean ready;
private static int number;
private static class ReaderThread extends Thread{
public void run(){
while(!ready)
Thread.yield();
System.out.println(number);
}
}
public static void main(String[] args){
new ReaderThread().start();
number = 42;
ready = true;
}
}
For the main thread launched by the JVM, it is guaranteed that statement 1 will be executed before statement 2 .
I understand very well that ReaderThread may not see the updated value above two static variables. I do not ask permission. But if statement 1 was executed before statement 2, is it possible for ReaderThread to display the updated value ready , and not for number ? Is that what reordering means ?
-
, , , , .
-
... , ... -
- ( ) .
, , " , "? , , . ?