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

Comparing jsr166/src/test/tck/ReentrantLockTest.java (file contents):
Revision 1.22 by dl, Tue May 3 16:02:00 2005 UTC vs.
Revision 1.23 by dl, Sun Aug 14 15:25:22 2005 UTC

# Line 1066 | Line 1066 | public class ReentrantLockTest extends J
1066      }
1067  
1068      /**
1069 +     * await after multiple reentrant locking preserves lock count
1070 +     */
1071 +    public void testAwaitLockCount() {
1072 +        final ReentrantLock lock = new ReentrantLock();
1073 +        final Condition c = lock.newCondition();
1074 +        Thread t1 = new Thread(new Runnable() {
1075 +                public void run() {
1076 +                    try {
1077 +                        lock.lock();
1078 +                        threadAssertEquals(1, lock.getHoldCount());
1079 +                        c.await();
1080 +                        threadAssertEquals(1, lock.getHoldCount());
1081 +                        lock.unlock();
1082 +                    }
1083 +                    catch(InterruptedException e) {
1084 +                        threadUnexpectedException();
1085 +                    }
1086 +                }
1087 +            });
1088 +
1089 +        Thread t2 = new Thread(new Runnable() {
1090 +                public void run() {
1091 +                    try {
1092 +                        lock.lock();
1093 +                        lock.lock();
1094 +                        threadAssertEquals(2, lock.getHoldCount());
1095 +                        c.await();
1096 +                        threadAssertEquals(2, lock.getHoldCount());
1097 +                        lock.unlock();
1098 +                        lock.unlock();
1099 +                    }
1100 +                    catch(InterruptedException e) {
1101 +                        threadUnexpectedException();
1102 +                    }
1103 +                }
1104 +            });
1105 +
1106 +        try {
1107 +            t1.start();
1108 +            t2.start();
1109 +            Thread.sleep(SHORT_DELAY_MS);
1110 +            lock.lock();
1111 +            c.signalAll();
1112 +            lock.unlock();
1113 +            t1.join(SHORT_DELAY_MS);
1114 +            t2.join(SHORT_DELAY_MS);
1115 +            assertFalse(t1.isAlive());
1116 +            assertFalse(t2.isAlive());
1117 +        }
1118 +        catch (Exception ex) {
1119 +            unexpectedException();
1120 +        }
1121 +    }
1122 +
1123 +    /**
1124       * A serialized lock deserializes as unlocked
1125       */
1126      public void testSerialization() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines