--- jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2011/05/21 06:24:33 1.41 +++ jsr166/src/test/tck/AbstractQueuedSynchronizerTest.java 2013/05/02 18:01:09 1.44 @@ -121,7 +121,7 @@ public class AbstractQueuedSynchronizerT } /** A constant to clarify calls to checking methods below. */ - final static Thread[] NO_THREADS = new Thread[0]; + static final Thread[] NO_THREADS = new Thread[0]; /** * Spin-waits until sync.isQueued(t) becomes true. @@ -947,23 +947,23 @@ public class AbstractQueuedSynchronizerT } /** - * awaitUninterruptibly doesn't abort on interrupt + * awaitUninterruptibly is uninterruptible */ public void testAwaitUninterruptibly() { final Mutex sync = new Mutex(); final ConditionObject c = sync.newCondition(); - final BooleanLatch acquired = new BooleanLatch(); + final BooleanLatch pleaseInterrupt = new BooleanLatch(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() { sync.acquire(); - assertTrue(acquired.releaseShared(0)); + assertTrue(pleaseInterrupt.releaseShared(0)); c.awaitUninterruptibly(); assertTrue(Thread.interrupted()); assertHasWaitersLocked(sync, c, NO_THREADS); sync.release(); }}); - acquired.acquireShared(0); + pleaseInterrupt.acquireShared(0); sync.acquire(); assertHasWaitersLocked(sync, c, t); sync.release(); @@ -990,15 +990,15 @@ public class AbstractQueuedSynchronizerT public void testInterruptible(final AwaitMethod awaitMethod) { final Mutex sync = new Mutex(); final ConditionObject c = sync.newCondition(); - final BooleanLatch acquired = new BooleanLatch(); + final BooleanLatch pleaseInterrupt = new BooleanLatch(); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { sync.acquire(); - assertTrue(acquired.releaseShared(0)); + assertTrue(pleaseInterrupt.releaseShared(0)); await(c, awaitMethod); }}); - acquired.acquireShared(0); + pleaseInterrupt.acquireShared(0); t.interrupt(); awaitTermination(t); } @@ -1190,17 +1190,24 @@ public class AbstractQueuedSynchronizerT */ public void testTryAcquireSharedNanos_Timeout() { final BooleanLatch l = new BooleanLatch(); + final BooleanLatch observedQueued = new BooleanLatch(); + final long timeoutMillis = timeoutMillis(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertFalse(l.isSignalled()); - long startTime = System.nanoTime(); - long nanos = MILLISECONDS.toNanos(timeoutMillis()); - assertFalse(l.tryAcquireSharedNanos(0, nanos)); - assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); + for (long millis = timeoutMillis(); + !observedQueued.isSignalled(); + millis *= 2) { + long nanos = MILLISECONDS.toNanos(millis); + long startTime = System.nanoTime(); + assertFalse(l.tryAcquireSharedNanos(0, nanos)); + assertTrue(millisElapsedSince(startTime) >= millis); + } assertFalse(l.isSignalled()); }}); waitForQueuedThread(l, t); + observedQueued.releaseShared(0); assertFalse(l.isSignalled()); awaitTermination(t); assertFalse(l.isSignalled());