volatile int ready; // Initially 0, with VarHandle READY
int dinner; // mode does not matter here
Thread 1 | Thread 2
dinner = 17; | if (READY.getAcquire(this) == 1)
READY.setRelease(this, 1); | int d = dinner; // sees 17
< /code>
Es war mir jedoch nicht erfolgreich, die ursprünglichen Ergebnisse zu reproduzieren: < /p>
Code: Select all
Java Concurrency Stress Tests
---------------------------------------------------------------------------------
...
RESULT SAMPLES FREQ EXPECT DESCRIPTION
0 462,012 1.69% Interesting
17 26,856,279 98.31% Interesting
...
RESULT SAMPLES FREQ EXPECT DESCRIPTION
0 1,027,953,599 44.29% Interesting
17 1,292,906,829 55.71% Interesting
...
Code: Select all
@JCStressTest
@State
@Outcome(id = {"17"}, expect = ACCEPTABLE_INTERESTING)
@Outcome(id = {"0"}, expect = ACCEPTABLE_INTERESTING)
public class TestRA {
volatile int ready;
int dinner;
static final VarHandle READY;
static {
try {
READY = MethodHandles.lookup()
.findVarHandle(TestRA.class, "ready", int.class);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
@Actor
public void actor1(I_Result result) {
final int i = (int) READY.getAcquire(this);
if (i == 1) {
result.r1 = dinner;
}
}
@Actor
public void actor2() {
dinner = 17;
READY.setRelease(this, 1);
}
}
- OS: Windows 11
- cpu platform: x86_64
- jdk: graalvm-17 (17.0.7)