问题:如果为Thready创建两个单独的线程,那么在2个线程都运行完成后,字段x和y的值哪种组合是不可能的?
代码:下方所示
public class Thready implements Runnable {
int x = 1;
int y = 1;
public void run() {
if (x == 2) x = 0;
else incX();
if (y == 2) y = 0;
else y++;
}
public synchronized void incX() {
x = x + 1;
}
}
选项:
a) x
= 0, y
= 3
b) x
= 2, y
= 2
c) x
= 3, y
= 0
d) x
= 0, y
= 2
e) x
= 0, y
= 0