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.20 by dl, Fri Jul 2 10:24:00 2004 UTC vs.
Revision 1.22 by dl, Tue May 3 16:02:00 2005 UTC

# Line 691 | Line 691 | public class ReentrantReadWriteLockTest
691          final Condition c = lock.writeLock().newCondition();
692          try {
693              lock.writeLock().lock();
694            assertFalse(c.await(10, TimeUnit.MILLISECONDS));
694              lock.writeLock().unlock();
695          }
696          catch (Exception ex) {
# Line 708 | Line 707 | public class ReentrantReadWriteLockTest
707          try {
708              lock.writeLock().lock();
709              java.util.Date d = new java.util.Date();
711            assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
710              lock.writeLock().unlock();
711          }
712          catch (Exception ex) {
# Line 749 | Line 747 | public class ReentrantReadWriteLockTest
747          }
748      }
749  
750 +    /** A helper class for uninterruptible wait tests */
751 +    class UninterruptableThread extends Thread {
752 +        private Lock lock;
753 +        private Condition c;
754 +        
755 +        public volatile boolean canAwake = false;
756 +        public volatile boolean interrupted = false;
757 +        public volatile boolean lockStarted = false;
758 +        
759 +        public UninterruptableThread(Lock lock, Condition c) {
760 +            this.lock = lock;
761 +            this.c = c;
762 +        }
763 +        
764 +        public synchronized void run() {
765 +            lock.lock();
766 +            lockStarted = true;
767 +            
768 +            while (!canAwake) {
769 +                c.awaitUninterruptibly();
770 +            }
771 +            
772 +            interrupted = isInterrupted();
773 +            lock.unlock();
774 +        }
775 +    }
776 +
777      /**
778       * awaitUninterruptibly doesn't abort on interrupt
779       */
780      public void testAwaitUninterruptibly() {
781 <        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();      
781 >        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
782          final Condition c = lock.writeLock().newCondition();
783 <        Thread t = new Thread(new Runnable() {
759 <                public void run() {
760 <                    lock.writeLock().lock();
761 <                    c.awaitUninterruptibly();
762 <                    lock.writeLock().unlock();
763 <                }
764 <            });
783 >        UninterruptableThread thread = new UninterruptableThread(lock.writeLock(), c);
784  
785          try {
786 <            t.start();
787 <            Thread.sleep(SHORT_DELAY_MS);
788 <            t.interrupt();
786 >            thread.start();
787 >
788 >            while (!thread.lockStarted) {
789 >                Thread.sleep(100);
790 >            }
791 >
792              lock.writeLock().lock();
793 <            c.signal();
794 <            lock.writeLock().unlock();
795 <            assert(t.isInterrupted());
796 <            t.join(SHORT_DELAY_MS);
797 <            assertFalse(t.isAlive());
798 <        }
799 <        catch (Exception ex) {
793 >            try {
794 >                thread.interrupt();
795 >                thread.canAwake = true;
796 >                c.signal();
797 >            } finally {
798 >                lock.writeLock().unlock();
799 >            }
800 >
801 >            thread.join();
802 >            assertTrue(thread.interrupted);
803 >            assertFalse(thread.isAlive());
804 >        } catch (Exception ex) {
805              unexpectedException();
806          }
807      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines