import java.util.BitSet;
import java.util.concurrent.CountDownLatch;
public class AnExample {
public static void main(String[] args) throws Exception {
BitSet bs = new BitSet();
CountDownLatch latch = new CountDownLatch(1);
Thread t1 = new Thread(new Runnable() {
public void run() {
try {
latch.await();
Thread.sleep(1000);
} catch (Exception ex) {
}
bs.set(1);
}
});
Thread t2 = new Thread(new Runnable() {
public void run() {
try {
latch.await();
Thread.sleep(1000);
} catch (Exception e) {
}
bs.set(2);
}
});
t1.start();
t2.start();
latch.countDown();
t1.join();
t2.join();
// crucial part here:
System.out.println(bs.get(1));
System.out.println(bs.get(2));
}
}
public class AnExampleTest implements
Actor2_Arbiter1_Test<BitSet, BooleanResult2> {
@Override
public void actor1(BitSet s, BooleanResult2 r) {
s.set(1);
}
@Override
public void actor2(BitSet s, BooleanResult2 r) {
s.set(2);
}
@Override
public void arbiter1(BitSet s, BooleanResult2 r) {
r.r1 = s.get(1);
r.r2 = s.get(2);
}
@Override
public BitSet newState() {
return new BitSet();
}
@Override
public BooleanResult2 newResult() {
return new BooleanResult2();
}
}
<test name="org.openjdk.jcstress.tests.custom.AnExampleTest">
<contributed-by>Oleg Shelajev</contributed-by>
<description>
Tests if BitSet works well without synchronization.
</description>
<case>
<match>[true, true]</match>
<expect>ACCEPTABLE</expect>
<description>
Seeing all updates intact.
</description>
</case>
<case>
<match>[true, false]</match>
<expect>ACCEPTABLE_INTERESTING</expect>
<description>
T2 overwrites T1 result.
</description>
</case>
<case>
<match>[false, true]</match>
<expect>ACCEPTABLE_INTERESTING</expect>
<description>
T1 overwrites T2 result.
</description>
</case>
<unmatched>
<expect>FORBIDDEN</expect>
<description>
All other cases are unexpected.
</description>
</unmatched>
</test>
java -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-RestrictContended -jar tests-custom/target/jcstress.jar -t=".*AnExampleTest"
synchronized (bs) {
bs.set(1);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有