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

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

# Line 1005 | Line 1005 | public class ReentrantReadWriteLockTest
1005      }
1006  
1007      /**
1008 <     * awaitUninterruptibly doesn't abort on interrupt
1008 >     * awaitUninterruptibly is uninterruptible
1009       */
1010      public void testAwaitUninterruptibly()      { testAwaitUninterruptibly(false); }
1011      public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); }
1012      public void testAwaitUninterruptibly(boolean fair) {
1013          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
1014          final Condition c = lock.writeLock().newCondition();
1015 <        final CountDownLatch locked = new CountDownLatch(1);
1016 <        Thread t = newStartedThread(new CheckedRunnable() {
1015 >        final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
1016 >
1017 >        Thread t1 = newStartedThread(new CheckedRunnable() {
1018              public void realRun() {
1019 +                // Interrupt before awaitUninterruptibly
1020                  lock.writeLock().lock();
1021 <                locked.countDown();
1021 >                pleaseInterrupt.countDown();
1022 >                Thread.currentThread().interrupt();
1023                  c.awaitUninterruptibly();
1024                  assertTrue(Thread.interrupted());
1025                  lock.writeLock().unlock();
1026              }});
1027  
1028 <        await(locked);
1028 >        Thread t2 = newStartedThread(new CheckedRunnable() {
1029 >            public void realRun() {
1030 >                // Interrupt during awaitUninterruptibly
1031 >                lock.writeLock().lock();
1032 >                pleaseInterrupt.countDown();
1033 >                c.awaitUninterruptibly();
1034 >                assertTrue(Thread.interrupted());
1035 >                lock.writeLock().unlock();
1036 >            }});
1037 >
1038 >        await(pleaseInterrupt);
1039          lock.writeLock().lock();
1040          lock.writeLock().unlock();
1041 <        t.interrupt();
1042 <        long timeoutMillis = 10;
1043 <        assertThreadStaysAlive(t, timeoutMillis);
1041 >        t2.interrupt();
1042 >
1043 >        assertThreadStaysAlive(t1);
1044 >        assertTrue(t2.isAlive());
1045 >
1046          lock.writeLock().lock();
1047 <        c.signal();
1047 >        c.signalAll();
1048          lock.writeLock().unlock();
1049 <        awaitTermination(t);
1049 >
1050 >        awaitTermination(t1);
1051 >        awaitTermination(t2);
1052      }
1053  
1054      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines