@JCStressTest
@Outcome(id = "1, 1", expect = Expect.ACCEPTABLE, desc = "ordered")
@Outcome(id = "0, 1", expect = Expect.ACCEPTABLE, desc = "ordered")
@Outcome(id = "1, 0", expect = Expect.ACCEPTABLE, desc = "reordered")
@Outcome(id = "0, 0", expect = Expect.ACCEPTABLE, desc = "ordered")
@State
public class TestJUC {
private int x;
public TestJUC() {}
@Actor
public void actor1() {
x = 1;
}
@Actor
public void actor2(II_Result r) {
1.int a = x;
2.r.r1 = a;
3.int b = x;
4.r.r2 = b;
}
}
After passing the jcstress test, there will be no result of (1,0). In the actor 2 method, in order to ensure as-if-serial, statement 1 must be before statement 2 and statement 3 must be before statement 4 after reordering.
The following situation is possible.
int b = x;
int a = x;
r.r1 = a;
r.r2 = b;
This situation may result in (1,0), but after jctress testing, this result did not occur. Why is this?