I am watching video from java jpoint conference.
I have question about following slide from Alexey Shipilev report:
Excuse me for non-english on slide. Actually author says that it is impossible that variable set will be
r1 = 1 (Y)
r2 = 0 (x)
r3 = 1 (x)
r4 = 0 (Y)
According the video he implies that it is obviously.
Can someone clarify why this value set impossible according JMM?
P.S.
If I understand Alexey notation correct it respects the following code:
public class SequentialConsistency {
static volatile int x;
static volatile int y;
public static void main(String[] args) {
new Thread(new Runnable() {
@Override
public void run() {
x = 1;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
y = 1;
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("r1=" + x + ", r2=" + y);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("r3=" + x + ", r4=" + y);
}
}).start();
}
}
volatile x,y;
and doesn't have r3 and r4? – Jacindajacinta