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.23 by dl, Mon Aug 1 19:53:01 2005 UTC vs.
Revision 1.24 by dl, Tue Aug 2 11:34:04 2005 UTC

# Line 698 | Line 698 | public class ReentrantReadWriteLockTest
698          }
699      }
700  
701 +
702 +    /**
703 +     * Fair Read tryLock succeeds if readlocked but not writelocked
704 +     */
705 +    public void testTryLockWhenReadLockedFair() {
706 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
707 +        lock.readLock().lock();
708 +        Thread t = new Thread(new Runnable() {
709 +                public void run() {
710 +                    threadAssertTrue(lock.readLock().tryLock());
711 +                    lock.readLock().unlock();
712 +                }
713 +            });
714 +        try {
715 +            t.start();
716 +            t.join();
717 +            lock.readLock().unlock();
718 +        } catch(Exception e){
719 +            unexpectedException();
720 +        }
721 +    }
722 +
723 +    
724 +
725 +    /**
726 +     * Fair write tryLock fails when readlocked
727 +     */
728 +    public void testWriteTryLockWhenReadLockedFair() {
729 +        final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true);
730 +        lock.readLock().lock();
731 +        Thread t = new Thread(new Runnable() {
732 +                public void run() {
733 +                    threadAssertFalse(lock.writeLock().tryLock());
734 +                }
735 +            });
736 +        try {
737 +            t.start();
738 +            t.join();
739 +            lock.readLock().unlock();
740 +        } catch(Exception e){
741 +            unexpectedException();
742 +        }
743 +    }
744 +
745      
746  
747      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines