23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 */
33
34 /*
35 * @test
36 * @summary stress test for arrivals in a tiered phaser
37 * @run main TieredArriveLoops 300
38 */
39
40 import java.util.concurrent.Phaser;
41
42 public class TieredArriveLoops {
43 final long testDurationMillisDefault = 10L * 1000L;
44 final long testDurationMillis;
45 final long quittingTimeNanos;
46
47 TieredArriveLoops(String[] args) {
48 testDurationMillis = (args.length > 0) ?
49 Long.valueOf(args[0]) : testDurationMillisDefault;
50 quittingTimeNanos = System.nanoTime() +
51 testDurationMillis * 1000L * 1000L;
52 }
53
54 Runnable runner(final Phaser p) {
55 return new CheckedRunnable() { public void realRun() {
56 int prevPhase = p.register();
57 while (!p.isTerminated()) {
58 int phase = p.awaitAdvance(p.arrive());
59 if (phase < 0)
60 return;
61 equal(phase, (prevPhase + 1) & Integer.MAX_VALUE);
62 int ph = p.getPhase();
63 check(ph < 0 || ph == phase);
|
23 /*
24 * This file is available under and governed by the GNU General Public
25 * License version 2 only, as published by the Free Software Foundation.
26 * However, the following notice accompanied the original version of this
27 * file:
28 *
29 * Written by Doug Lea with assistance from members of JCP JSR-166
30 * Expert Group and released to the public domain, as explained at
31 * http://creativecommons.org/publicdomain/zero/1.0/
32 */
33
34 /*
35 * @test
36 * @summary stress test for arrivals in a tiered phaser
37 * @run main TieredArriveLoops 300
38 */
39
40 import java.util.concurrent.Phaser;
41
42 public class TieredArriveLoops {
43 final long testDurationMillisDefault = 10_000L;
44 final long testDurationMillis;
45 final long quittingTimeNanos;
46
47 TieredArriveLoops(String[] args) {
48 testDurationMillis = (args.length > 0) ?
49 Long.valueOf(args[0]) : testDurationMillisDefault;
50 quittingTimeNanos = System.nanoTime() +
51 testDurationMillis * 1000L * 1000L;
52 }
53
54 Runnable runner(final Phaser p) {
55 return new CheckedRunnable() { public void realRun() {
56 int prevPhase = p.register();
57 while (!p.isTerminated()) {
58 int phase = p.awaitAdvance(p.arrive());
59 if (phase < 0)
60 return;
61 equal(phase, (prevPhase + 1) & Integer.MAX_VALUE);
62 int ph = p.getPhase();
63 check(ph < 0 || ph == phase);
|