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.47 by jsr166, Mon May 2 00:04:49 2011 UTC vs.
Revision 1.52 by jsr166, Mon May 2 00:34:12 2011 UTC

# Line 241 | Line 241 | public class ReentrantReadWriteLockTest
241  
242          Thread.sleep(SHORT_DELAY_MS);
243          t.interrupt();
244        Thread.sleep(SHORT_DELAY_MS);
245        lock.writeLock().unlock();
244          t.join();
245 +        releaseLock(lock.writeLock());
246      }
247  
248      /**
# Line 260 | Line 259 | public class ReentrantReadWriteLockTest
259          Thread.sleep(SHORT_DELAY_MS);
260          t.interrupt();
261          t.join();
262 +        releaseLock(lock.writeLock());
263      }
264  
265  
# Line 682 | Line 682 | public class ReentrantReadWriteLockTest
682  
683          Thread.sleep(SHORT_DELAY_MS);
684          t.interrupt();
685        Thread.sleep(SHORT_DELAY_MS);
685          t.join();
686 <        lock.writeLock().unlock();
686 >        releaseLock(lock.writeLock());
687      }
688  
689      /**
# Line 701 | Line 700 | public class ReentrantReadWriteLockTest
700          Thread.sleep(SHORT_DELAY_MS);
701          t.interrupt();
702          t.join();
703 <        lock.writeLock().unlock();
703 >        releaseLock(lock.writeLock());
704      }
705  
706      /**
# Line 847 | Line 846 | public class ReentrantReadWriteLockTest
846      public void testAwait_Interrupt() throws InterruptedException {
847          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
848          final Condition c = lock.writeLock().newCondition();
849 +        final CountDownLatch locked = new CountDownLatch(1);
850          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
851              public void realRun() throws InterruptedException {
852                  lock.writeLock().lock();
853 <                c.await();
854 <                lock.writeLock().unlock();
853 >                assertTrue(lock.isWriteLocked());
854 >                locked.countDown();
855 >                try { c.await(); }
856 >                finally { lock.writeLock().unlock(); }
857              }});
858  
859 <        Thread.sleep(SHORT_DELAY_MS);
859 >        locked.await();
860 >        while (lock.isWriteLocked())
861 >            Thread.yield();
862          t.interrupt();
863 <        t.join(SHORT_DELAY_MS);
864 <        assertFalse(t.isAlive());
863 >        awaitTermination(t, LONG_DELAY_MS);
864 >        assertFalse(lock.isWriteLocked());
865      }
866  
867      /**
# Line 866 | Line 870 | public class ReentrantReadWriteLockTest
870      public void testAwaitNanos_Interrupt() throws InterruptedException {
871          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
872          final Condition c = lock.writeLock().newCondition();
873 +        final CountDownLatch locked = new CountDownLatch(1);
874          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
875              public void realRun() throws InterruptedException {
876                  lock.writeLock().lock();
877 <                c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS));
878 <                lock.writeLock().unlock();
877 >                assertTrue(lock.isWriteLocked());
878 >                locked.countDown();
879 >                try { c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); }
880 >                finally { lock.writeLock().unlock(); }
881              }});
882  
883 <        Thread.sleep(SHORT_DELAY_MS);
883 >        locked.await();
884 >        while (lock.isWriteLocked())
885 >            Thread.yield();
886          t.interrupt();
887 <        t.join(SHORT_DELAY_MS);
888 <        assertFalse(t.isAlive());
887 >        awaitTermination(t, LONG_DELAY_MS);
888 >        assertFalse(lock.isWriteLocked());
889      }
890  
891      /**
# Line 885 | Line 894 | public class ReentrantReadWriteLockTest
894      public void testAwaitUntil_Interrupt() throws InterruptedException {
895          final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
896          final Condition c = lock.writeLock().newCondition();
897 +        final CountDownLatch locked = new CountDownLatch(1);
898          Thread t = newStartedThread(new CheckedInterruptedRunnable() {
899              public void realRun() throws InterruptedException {
900                  lock.writeLock().lock();
901 +                assertTrue(lock.isWriteLocked());
902 +                locked.countDown();
903                  java.util.Date d = new java.util.Date();
904 <                c.awaitUntil(new java.util.Date(d.getTime() + 10000));
905 <                lock.writeLock().unlock();
904 >                try { c.awaitUntil(new java.util.Date(d.getTime() + 10000)); }
905 >                finally { lock.writeLock().unlock(); }
906              }});
907  
908 <        Thread.sleep(SHORT_DELAY_MS);
908 >        locked.await();
909 >        while (lock.isWriteLocked())
910 >            Thread.yield();
911          t.interrupt();
912 <        t.join(SHORT_DELAY_MS);
913 <        assertFalse(t.isAlive());
912 >        awaitTermination(t, LONG_DELAY_MS);
913 >        assertFalse(lock.isWriteLocked());
914      }
915  
916      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines