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.79 by jsr166, Sun Jan 1 20:34:39 2017 UTC vs.
Revision 1.81 by jsr166, Mon Jul 17 21:01:30 2017 UTC

# Line 21 | Line 21 | import junit.framework.AssertionFailedEr
21   import junit.framework.Test;
22   import junit.framework.TestSuite;
23  
24 + @SuppressWarnings("WaitNotInLoop") // we implement spurious-wakeup freedom
25   public class ReentrantReadWriteLockTest extends JSR166TestCase {
26      public static void main(String[] args) {
27          main(suite(), args);
# Line 1009 | Line 1010 | public class ReentrantReadWriteLockTest
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();
1013 >        final Lock lock = new ReentrantReadWriteLock(fair).writeLock();
1014 >        final Condition condition = lock.newCondition();
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();
1020 >                lock.lock();
1021                  pleaseInterrupt.countDown();
1022                  Thread.currentThread().interrupt();
1023 <                c.awaitUninterruptibly();
1023 >                condition.awaitUninterruptibly();
1024                  assertTrue(Thread.interrupted());
1025 <                lock.writeLock().unlock();
1025 >                lock.unlock();
1026              }});
1027  
1028          Thread t2 = newStartedThread(new CheckedRunnable() {
1029              public void realRun() {
1030                  // Interrupt during awaitUninterruptibly
1031 <                lock.writeLock().lock();
1031 >                lock.lock();
1032                  pleaseInterrupt.countDown();
1033 <                c.awaitUninterruptibly();
1033 >                condition.awaitUninterruptibly();
1034                  assertTrue(Thread.interrupted());
1035 <                lock.writeLock().unlock();
1035 >                lock.unlock();
1036              }});
1037  
1038          await(pleaseInterrupt);
1038        lock.writeLock().lock();
1039        lock.writeLock().unlock();
1039          t2.interrupt();
1040 <
1041 <        assertThreadStaysAlive(t1);
1042 <        assertTrue(t2.isAlive());
1043 <
1044 <        lock.writeLock().lock();
1045 <        c.signalAll();
1046 <        lock.writeLock().unlock();
1040 >        lock.lock();
1041 >        lock.unlock();
1042 >        assertThreadBlocks(t1, Thread.State.WAITING);
1043 >        assertThreadBlocks(t2, Thread.State.WAITING);
1044 >
1045 >        lock.lock();
1046 >        condition.signalAll();
1047 >        lock.unlock();
1048  
1049          awaitTermination(t1);
1050          awaitTermination(t2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines