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

Comparing jsr166/src/test/tck/PhaserTest.java (file contents):
Revision 1.15 by jsr166, Sat Oct 9 19:30:35 2010 UTC vs.
Revision 1.16 by jsr166, Mon Oct 11 05:35:19 2010 UTC

# Line 8 | Line 8
8   import java.util.ArrayList;
9   import java.util.List;
10   import java.util.concurrent.atomic.AtomicInteger;
11 + import java.util.concurrent.atomic.AtomicBoolean;
12   import java.util.concurrent.*;
13 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
14   import junit.framework.Test;
15   import junit.framework.TestSuite;
16  
# Line 445 | Line 447 | public class PhaserTest extends JSR166Te
447       */
448      public void testArriveAndAwaitAdvance2() throws InterruptedException {
449          final Phaser phaser = new Phaser(2);
450 <        Thread th = newStartedThread(new CheckedRunnable() {
451 <            public void realRun() {
450 >        final CountDownLatch threadStarted = new CountDownLatch(1);
451 >        final AtomicBoolean advanced = new AtomicBoolean(false);
452 >        final AtomicBoolean checkedInterruptStatus = new AtomicBoolean(false);
453 >        Thread t = newStartedThread(new CheckedRunnable() {
454 >            public void realRun() throws InterruptedException {
455 >                threadStarted.countDown();
456                  phaser.arriveAndAwaitAdvance();
457 +                advanced.set(true);
458 +                assertTrue(Thread.currentThread().isInterrupted());
459 +                while (!checkedInterruptStatus.get())
460 +                    Thread.yield();
461              }});
462  
463 <        Thread.sleep(SMALL_DELAY_MS);
464 <        th.interrupt();
455 <        Thread.sleep(SMALL_DELAY_MS);
463 >        assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS));
464 >        t.interrupt();
465          phaser.arrive();
466 <        assertFalse(th.isInterrupted());
467 <        th.join();
466 >        while (!advanced.get())
467 >            Thread.yield();
468 >        assertTrue(t.isInterrupted());
469 >        checkedInterruptStatus.set(true);
470 >        awaitTermination(t, SMALL_DELAY_MS);
471      }
472  
473      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines