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

Comparing jsr166/src/test/tck/SemaphoreTest.java (file contents):
Revision 1.29 by jsr166, Tue May 31 16:16:24 2011 UTC vs.
Revision 1.30 by jsr166, Fri Jun 3 05:07:14 2011 UTC

# Line 223 | Line 223 | public class SemaphoreTest extends JSR16
223      public void testInterruptible_tryAcquireTimedN_fair() { testInterruptible(true,  AcquireMethod.tryAcquireTimedN); }
224      public void testInterruptible(boolean fair, final AcquireMethod acquirer) {
225          final PublicSemaphore s = new PublicSemaphore(0, fair);
226 <        final Semaphore anotherInterruptPlease = new Semaphore(0, fair);
226 >        final Semaphore pleaseInterrupt = new Semaphore(0, fair);
227          Thread t = newStartedThread(new CheckedRunnable() {
228              public void realRun() {
229                  // Interrupt before acquire
# Line 246 | Line 246 | public class SemaphoreTest extends JSR16
246                      shouldThrow();
247                  } catch (InterruptedException success) {}
248  
249 <                anotherInterruptPlease.release();
249 >                pleaseInterrupt.release();
250  
251                  // Interrupt during acquire(N)
252                  try {
# Line 257 | Line 257 | public class SemaphoreTest extends JSR16
257  
258          waitForQueuedThread(s, t);
259          t.interrupt();
260 <        try {
261 <            assertTrue(anotherInterruptPlease.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
262 <        } catch (InterruptedException e) { threadUnexpectedException(e); }
260 >        await(pleaseInterrupt);
261          waitForQueuedThread(s, t);
262          t.interrupt();
263          awaitTermination(t);
# Line 275 | Line 273 | public class SemaphoreTest extends JSR16
273      public void testUninterruptible_acquireUninterruptiblyN_fair() { testUninterruptible(true,  AcquireMethod.acquireUninterruptiblyN); }
274      public void testUninterruptible(boolean fair, final AcquireMethod acquirer) {
275          final PublicSemaphore s = new PublicSemaphore(0, fair);
276 <        final Semaphore anotherInterruptPlease = new Semaphore(0, fair);
277 <        Thread t = newStartedThread(new CheckedRunnable() {
276 >        final Semaphore pleaseInterrupt = new Semaphore(-1, fair);
277 >
278 >        Thread t1 = newStartedThread(new CheckedRunnable() {
279              public void realRun() throws InterruptedException {
280                  // Interrupt before acquire
281 +                pleaseInterrupt.release();
282                  Thread.currentThread().interrupt();
283                  acquirer.acquire(s);
284                  assertTrue(Thread.interrupted());
285 +            }});
286  
287 <                anotherInterruptPlease.release();
288 <
287 >        Thread t2 = newStartedThread(new CheckedRunnable() {
288 >            public void realRun() throws InterruptedException {
289                  // Interrupt during acquire
290 +                pleaseInterrupt.release();
291                  acquirer.acquire(s);
292                  assertTrue(Thread.interrupted());
293              }});
294  
295 <        waitForQueuedThread(s, t);
296 <        assertThreadStaysAlive(t);
297 <        s.release();
295 >        await(pleaseInterrupt);
296 >        waitForQueuedThread(s, t1);
297 >        waitForQueuedThread(s, t2);
298 >        t2.interrupt();
299  
300 <        try {
301 <            assertTrue(anotherInterruptPlease.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
299 <        } catch (InterruptedException e) { threadUnexpectedException(e); }
300 <        waitForQueuedThread(s, t);
301 <        t.interrupt();
302 <        assertThreadStaysAlive(t);
303 <        s.release();
300 >        assertThreadStaysAlive(t1);
301 >        assertTrue(t2.isAlive());
302  
303 <        awaitTermination(t);
303 >        s.release(2);
304 >
305 >        awaitTermination(t1);
306 >        awaitTermination(t2);
307      }
308  
309      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines