提交 69603e4f 编写于 作者: D dl

7058828: test/java/util/concurrent/Phaser/Arrive.java fails intermittently

Reviewed-by: chegar
上级 c914ddde
...@@ -45,9 +45,12 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -45,9 +45,12 @@ import java.util.concurrent.atomic.AtomicInteger;
public class Arrive { public class Arrive {
void test(String[] args) throws Throwable { void test(String[] args) throws Throwable {
for (int i = 0; i < 100; ++i)
doTest(args);
}
void doTest(String[] args) throws Throwable {
final int n = ThreadLocalRandom.current().nextInt(1, 10); final int n = ThreadLocalRandom.current().nextInt(1, 10);
final int nthreads = n*3/2; final Phaser startingGate = new Phaser(n);
final Phaser startingGate = new Phaser(nthreads);
final Phaser phaser = new Phaser(n); final Phaser phaser = new Phaser(n);
final List<Thread> threads = new ArrayList<Thread>(); final List<Thread> threads = new ArrayList<Thread>();
final AtomicInteger count0 = new AtomicInteger(0); final AtomicInteger count0 = new AtomicInteger(0);
...@@ -64,14 +67,14 @@ public class Arrive { ...@@ -64,14 +67,14 @@ public class Arrive {
else else
fail(); fail();
}}; }};
for (int i = 0; i < nthreads; i++) for (int i = 0; i < n; i++)
threads.add(new Thread(task)); threads.add(new Thread(task));
for (Thread thread : threads) for (Thread thread : threads)
thread.start(); thread.start();
for (Thread thread : threads) for (Thread thread : threads)
thread.join(); thread.join();
equal(count0.get(), n); equal(count0.get(), n);
equal(count1.get(), nthreads-n); equal(count1.get(), 0);
equal(phaser.getPhase(), 1); equal(phaser.getPhase(), 1);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册