--- jsr166/src/test/tck/PhaserTest.java 2010/10/09 19:30:35 1.15 +++ jsr166/src/test/tck/PhaserTest.java 2010/10/11 07:43:53 1.17 @@ -8,7 +8,9 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.*; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import junit.framework.Test; import junit.framework.TestSuite; @@ -328,19 +330,19 @@ public class PhaserTest extends JSR166Te public void testAwaitAdvance3() throws InterruptedException { final Phaser phaser = new Phaser(); phaser.register(); + final CountDownLatch threadStarted = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { phaser.register(); - sleepTillInterrupted(LONG_DELAY_MS); + threadStarted.countDown(); phaser.awaitAdvance(phaser.arrive()); + assertTrue(Thread.currentThread().isInterrupted()); }}); - Thread.sleep(SMALL_DELAY_MS); + assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); t.interrupt(); - Thread.sleep(SMALL_DELAY_MS); phaser.arrive(); - assertFalse(t.isInterrupted()); - t.join(); + awaitTermination(t, SMALL_DELAY_MS); } /** @@ -445,17 +447,27 @@ public class PhaserTest extends JSR166Te */ public void testArriveAndAwaitAdvance2() throws InterruptedException { final Phaser phaser = new Phaser(2); - Thread th = newStartedThread(new CheckedRunnable() { - public void realRun() { + final CountDownLatch threadStarted = new CountDownLatch(1); + final AtomicBoolean advanced = new AtomicBoolean(false); + final AtomicBoolean checkedInterruptStatus = new AtomicBoolean(false); + Thread t = newStartedThread(new CheckedRunnable() { + public void realRun() throws InterruptedException { + threadStarted.countDown(); phaser.arriveAndAwaitAdvance(); + advanced.set(true); + assertTrue(Thread.currentThread().isInterrupted()); + while (!checkedInterruptStatus.get()) + Thread.yield(); }}); - Thread.sleep(SMALL_DELAY_MS); - th.interrupt(); - Thread.sleep(SMALL_DELAY_MS); + assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); + t.interrupt(); phaser.arrive(); - assertFalse(th.isInterrupted()); - th.join(); + while (!advanced.get()) + Thread.yield(); + assertTrue(t.isInterrupted()); + checkedInterruptStatus.set(true); + awaitTermination(t, SMALL_DELAY_MS); } /**