ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CyclicBarrierTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CyclicBarrierTest.java (file contents):
Revision 1.22 by dl, Sun May 29 13:16:40 2011 UTC vs.
Revision 1.23 by jsr166, Sun May 29 15:31:36 2011 UTC

# Line 27 | Line 27 | public class CyclicBarrierTest extends J
27      }
28  
29      /**
30 +     * Spin-waits till the number of waiters == numberOfWaiters.
31 +     */
32 +    void awaitNumberWaiting(CyclicBarrier barrier, int numberOfWaiters) {
33 +        long startTime = System.nanoTime();
34 +        while (barrier.getNumberWaiting() != numberOfWaiters) {
35 +            if (millisElapsedSince(startTime) > LONG_DELAY_MS)
36 +                fail("timed out");
37 +            Thread.yield();
38 +        }
39 +    }
40 +
41 +    /**
42       * Creating with negative parties throws IAE
43       */
44      public void testConstructor1() {
# Line 186 | Line 198 | public class CyclicBarrierTest extends J
198              }});
199          Thread t2 = newStartedThread(new CheckedRunnable() {
200              public void realRun() throws Exception {
201 <                while (c.getNumberWaiting() == 0)
190 <                    Thread.yield();
201 >                awaitNumberWaiting(c, 1);
202                  long startTime = System.nanoTime();
203                  try {
204                      c.await(timeoutMillis(), MILLISECONDS);
# Line 215 | Line 226 | public class CyclicBarrierTest extends J
226              }});
227          Thread t2 = newStartedThread(new CheckedRunnable() {
228              public void realRun() throws Exception {
229 <                while (c.getNumberWaiting() == 0)
219 <                    Thread.yield();
229 >                awaitNumberWaiting(c, 1);
230                  long startTime = System.nanoTime();
231                  try {
232                      c.await(timeoutMillis(), MILLISECONDS);
# Line 234 | Line 244 | public class CyclicBarrierTest extends J
244       * BrokenBarrierException
245       */
246      public void testReset_BrokenBarrier() throws InterruptedException {
237        Thread.interrupted(); // ensure current thread not interrupted
247          final CyclicBarrier c = new CyclicBarrier(3);
248          final CountDownLatch pleaseReset = new CountDownLatch(2);
249          Thread t1 = new ThreadShouldThrow(BrokenBarrierException.class) {
# Line 251 | Line 260 | public class CyclicBarrierTest extends J
260          t1.start();
261          t2.start();
262          await(pleaseReset);
263 +
264 +        awaitNumberWaiting(c, 2);
265          c.reset();
266          awaitTermination(t1);
267          awaitTermination(t2);
# Line 387 | Line 398 | public class CyclicBarrierTest extends J
398                  }});
399              Thread t2 = newStartedThread(new CheckedRunnable() {
400                  public void realRun() throws Exception {
401 <                    while (barrier.getNumberWaiting() == 0)
391 <                        Thread.yield();
401 >                    awaitNumberWaiting(barrier, 1);
402                      long startTime = System.nanoTime();
403                      try {
404                          barrier.await(timeoutMillis(), MILLISECONDS);
# Line 433 | Line 443 | public class CyclicBarrierTest extends J
443              t1.start();
444              t2.start();
445              start.await();
446 <            while (barrier.getNumberWaiting() < 2) { Thread.yield(); }
446 >            awaitNumberWaiting(barrier, 2);
447              try {
448                  barrier.await();
449                  shouldThrow();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines