author | dl |
Fri, 01 Nov 2019 09:07:59 -0700 | |
changeset 58893 | ec954ef6caf1 |
parent 54686 | 09f09b4e7808 |
permissions | -rw-r--r-- |
35394 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
6 |
* published by the Free Software Foundation. |
|
7 |
* |
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
12 |
* accompanied this code). |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License version |
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 |
* |
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 |
* or visit www.oracle.com if you need additional information or have any |
|
20 |
* questions. |
|
21 |
*/ |
|
22 |
||
23 |
/* |
|
24 |
* This file is available under and governed by the GNU General Public |
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
|
26 |
* However, the following notice accompanied the original version of this |
|
27 |
* file: |
|
28 |
* |
|
29 |
* Written by Doug Lea and Martin Buchholz |
|
30 |
* with assistance from members of JCP JSR-166 Expert Group and |
|
31 |
* released to the public domain, as explained at |
|
32 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
|
33 |
*/ |
|
34 |
||
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
35 |
import static java.util.concurrent.TimeUnit.DAYS; |
35394 | 36 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
37 |
||
47343 | 38 |
import static java.util.concurrent.locks.StampedLock.isLockStamp; |
39 |
import static java.util.concurrent.locks.StampedLock.isOptimisticReadStamp; |
|
40 |
import static java.util.concurrent.locks.StampedLock.isReadLockStamp; |
|
41 |
import static java.util.concurrent.locks.StampedLock.isWriteLockStamp; |
|
42 |
||
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
43 |
import java.util.ArrayList; |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
44 |
import java.util.List; |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
45 |
import java.util.concurrent.Callable; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
46 |
import java.util.concurrent.CompletableFuture; |
35394 | 47 |
import java.util.concurrent.CountDownLatch; |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
48 |
import java.util.concurrent.Future; |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
49 |
import java.util.concurrent.ThreadLocalRandom; |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
50 |
import java.util.concurrent.TimeUnit; |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
51 |
import java.util.concurrent.atomic.AtomicBoolean; |
35394 | 52 |
import java.util.concurrent.locks.Lock; |
53 |
import java.util.concurrent.locks.StampedLock; |
|
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
54 |
import java.util.function.BiConsumer; |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
55 |
import java.util.function.Consumer; |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
56 |
import java.util.function.Function; |
35394 | 57 |
|
58 |
import junit.framework.Test; |
|
59 |
import junit.framework.TestSuite; |
|
60 |
||
61 |
public class StampedLockTest extends JSR166TestCase { |
|
62 |
public static void main(String[] args) { |
|
63 |
main(suite(), args); |
|
64 |
} |
|
65 |
public static Test suite() { |
|
66 |
return new TestSuite(StampedLockTest.class); |
|
67 |
} |
|
68 |
||
69 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
70 |
* Releases write lock, checking isWriteLocked before and after |
35394 | 71 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
72 |
void releaseWriteLock(StampedLock lock, long stamp) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
73 |
assertTrue(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
74 |
assertValid(lock, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
75 |
lock.unlockWrite(stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
76 |
assertFalse(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
77 |
assertFalse(lock.validate(stamp)); |
35394 | 78 |
} |
79 |
||
80 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
81 |
* Releases read lock, checking isReadLocked before and after |
35394 | 82 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
83 |
void releaseReadLock(StampedLock lock, long stamp) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
84 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
85 |
assertValid(lock, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
86 |
lock.unlockRead(stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
87 |
assertFalse(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
88 |
assertTrue(lock.validate(stamp)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
89 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
90 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
91 |
long assertNonZero(long v) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
92 |
assertTrue(v != 0L); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
93 |
return v; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
94 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
95 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
96 |
long assertValid(StampedLock lock, long stamp) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
97 |
assertTrue(stamp != 0L); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
98 |
assertTrue(lock.validate(stamp)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
99 |
return stamp; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
100 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
101 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
102 |
void assertUnlocked(StampedLock lock) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
103 |
assertFalse(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
104 |
assertFalse(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
105 |
assertEquals(0, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
106 |
assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
107 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
108 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
109 |
List<Action> lockLockers(Lock lock) { |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
110 |
return List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
111 |
() -> lock.lock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
112 |
() -> lock.lockInterruptibly(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
113 |
() -> lock.tryLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
114 |
() -> lock.tryLock(Long.MIN_VALUE, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
115 |
() -> lock.tryLock(0L, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
116 |
() -> lock.tryLock(Long.MAX_VALUE, DAYS)); |
35394 | 117 |
} |
118 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
119 |
List<Function<StampedLock, Long>> readLockers() { |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
120 |
return List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
121 |
sl -> sl.readLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
122 |
sl -> sl.tryReadLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
123 |
sl -> readLockInterruptiblyUninterrupted(sl), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
124 |
sl -> tryReadLockUninterrupted(sl, Long.MIN_VALUE, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
125 |
sl -> tryReadLockUninterrupted(sl, 0L, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
126 |
sl -> sl.tryConvertToReadLock(sl.tryOptimisticRead())); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
127 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
128 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
129 |
List<BiConsumer<StampedLock, Long>> readUnlockers() { |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
130 |
return List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
131 |
(sl, stamp) -> sl.unlockRead(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
132 |
(sl, stamp) -> assertTrue(sl.tryUnlockRead()), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
133 |
(sl, stamp) -> sl.asReadLock().unlock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
134 |
(sl, stamp) -> sl.unlock(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
135 |
(sl, stamp) -> assertValid(sl, sl.tryConvertToOptimisticRead(stamp))); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
136 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
137 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
138 |
List<Function<StampedLock, Long>> writeLockers() { |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
139 |
return List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
140 |
sl -> sl.writeLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
141 |
sl -> sl.tryWriteLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
142 |
sl -> writeLockInterruptiblyUninterrupted(sl), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
143 |
sl -> tryWriteLockUninterrupted(sl, Long.MIN_VALUE, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
144 |
sl -> tryWriteLockUninterrupted(sl, 0L, DAYS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
145 |
sl -> sl.tryConvertToWriteLock(sl.tryOptimisticRead())); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
146 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
147 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
148 |
List<BiConsumer<StampedLock, Long>> writeUnlockers() { |
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
149 |
return List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
150 |
(sl, stamp) -> sl.unlockWrite(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
151 |
(sl, stamp) -> assertTrue(sl.tryUnlockWrite()), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
152 |
(sl, stamp) -> sl.asWriteLock().unlock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
153 |
(sl, stamp) -> sl.unlock(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
154 |
(sl, stamp) -> assertValid(sl, sl.tryConvertToOptimisticRead(stamp))); |
35394 | 155 |
} |
156 |
||
157 |
/** |
|
158 |
* Constructed StampedLock is in unlocked state |
|
159 |
*/ |
|
160 |
public void testConstructor() { |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
161 |
assertUnlocked(new StampedLock()); |
35394 | 162 |
} |
163 |
||
164 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
165 |
* write-locking, then unlocking, an unlocked lock succeed |
35394 | 166 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
167 |
public void testWriteLock_lockUnlock() { |
35394 | 168 |
StampedLock lock = new StampedLock(); |
169 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
170 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
171 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
172 |
assertFalse(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
173 |
assertFalse(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
174 |
assertEquals(0, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
175 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
176 |
long s = writeLocker.apply(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
177 |
assertValid(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
178 |
assertTrue(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
179 |
assertFalse(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
180 |
assertEquals(0, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
181 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
182 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
183 |
} |
35394 | 184 |
} |
185 |
||
186 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
187 |
* read-locking, then unlocking, an unlocked lock succeed |
35394 | 188 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
189 |
public void testReadLock_lockUnlock() { |
35394 | 190 |
StampedLock lock = new StampedLock(); |
191 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
192 |
for (Function<StampedLock, Long> readLocker : readLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
193 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
194 |
long s = 42; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
195 |
for (int i = 0; i < 2; i++) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
196 |
s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
197 |
assertFalse(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
198 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
199 |
assertEquals(i + 1, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
200 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
201 |
for (int i = 0; i < 2; i++) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
202 |
assertFalse(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
203 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
204 |
assertEquals(2 - i, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
205 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
206 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
207 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
208 |
} |
35394 | 209 |
} |
210 |
||
211 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
212 |
* tryUnlockWrite fails if not write locked |
35394 | 213 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
214 |
public void testTryUnlockWrite_failure() { |
35394 | 215 |
StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
216 |
assertFalse(lock.tryUnlockWrite()); |
35394 | 217 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
218 |
for (Function<StampedLock, Long> readLocker : readLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
219 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
220 |
long s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
221 |
assertFalse(lock.tryUnlockWrite()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
222 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
223 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
224 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
225 |
} |
35394 | 226 |
} |
227 |
||
228 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
229 |
* tryUnlockRead fails if not read locked |
35394 | 230 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
231 |
public void testTryUnlockRead_failure() { |
35394 | 232 |
StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
233 |
assertFalse(lock.tryUnlockRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
234 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
235 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
236 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
237 |
long s = writeLocker.apply(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
238 |
assertFalse(lock.tryUnlockRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
239 |
assertTrue(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
240 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
241 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
242 |
} |
35394 | 243 |
} |
244 |
||
245 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
246 |
* validate(0L) fails |
35394 | 247 |
*/ |
248 |
public void testValidate0() { |
|
249 |
StampedLock lock = new StampedLock(); |
|
250 |
assertFalse(lock.validate(0L)); |
|
251 |
} |
|
252 |
||
253 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
254 |
* A stamp obtained from a successful lock operation validates while the lock is held |
35394 | 255 |
*/ |
256 |
public void testValidate() throws InterruptedException { |
|
257 |
StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
258 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
259 |
for (Function<StampedLock, Long> readLocker : readLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
260 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
261 |
long s = assertNonZero(readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
262 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
263 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
264 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
265 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
266 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
267 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
268 |
long s = assertNonZero(writeLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
269 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
270 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
271 |
} |
35394 | 272 |
} |
273 |
||
274 |
/** |
|
275 |
* A stamp obtained from an unsuccessful lock operation does not validate |
|
276 |
*/ |
|
277 |
public void testValidate2() throws InterruptedException { |
|
278 |
StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
279 |
long s = assertNonZero(lock.writeLock()); |
35394 | 280 |
assertTrue(lock.validate(s)); |
281 |
assertFalse(lock.validate(lock.tryWriteLock())); |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
282 |
assertFalse(lock.validate(lock.tryWriteLock(randomExpiredTimeout(), |
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
283 |
randomTimeUnit()))); |
35394 | 284 |
assertFalse(lock.validate(lock.tryReadLock())); |
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
285 |
assertFalse(lock.validate(lock.tryWriteLock(randomExpiredTimeout(), |
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
286 |
randomTimeUnit()))); |
35394 | 287 |
assertFalse(lock.validate(lock.tryOptimisticRead())); |
288 |
lock.unlockWrite(s); |
|
289 |
} |
|
290 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
291 |
void assertThrowInterruptedExceptionWhenPreInterrupted(Action[] actions) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
292 |
for (Action action : actions) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
293 |
Thread.currentThread().interrupt(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
294 |
try { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
295 |
action.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
296 |
shouldThrow(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
297 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
298 |
catch (InterruptedException success) {} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
299 |
catch (Throwable fail) { threadUnexpectedException(fail); } |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
300 |
assertFalse(Thread.interrupted()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
301 |
} |
35394 | 302 |
} |
303 |
||
304 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
305 |
* interruptible operations throw InterruptedException when pre-interrupted |
35394 | 306 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
307 |
public void testInterruptibleOperationsThrowInterruptedExceptionWhenPreInterrupted() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
308 |
final StampedLock lock = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
309 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
310 |
Action[] interruptibleLockActions = { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
311 |
() -> lock.writeLockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
312 |
() -> lock.tryWriteLock(Long.MIN_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
313 |
() -> lock.tryWriteLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
314 |
() -> lock.readLockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
315 |
() -> lock.tryReadLock(Long.MIN_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
316 |
() -> lock.tryReadLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
317 |
() -> lock.asWriteLock().lockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
318 |
() -> lock.asWriteLock().tryLock(0L, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
319 |
() -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
320 |
() -> lock.asReadLock().lockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
321 |
() -> lock.asReadLock().tryLock(0L, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
322 |
() -> lock.asReadLock().tryLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
323 |
}; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
324 |
shuffle(interruptibleLockActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
325 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
326 |
assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
327 |
{ |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
328 |
long s = lock.writeLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
329 |
assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
330 |
lock.unlockWrite(s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
331 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
332 |
{ |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
333 |
long s = lock.readLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
334 |
assertThrowInterruptedExceptionWhenPreInterrupted(interruptibleLockActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
335 |
lock.unlockRead(s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
336 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
337 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
338 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
339 |
void assertThrowInterruptedExceptionWhenInterrupted(Action[] actions) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
340 |
int n = actions.length; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
341 |
Future<?>[] futures = new Future<?>[n]; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
342 |
CountDownLatch threadsStarted = new CountDownLatch(n); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
343 |
CountDownLatch done = new CountDownLatch(n); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
344 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
345 |
for (int i = 0; i < n; i++) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
346 |
Action action = actions[i]; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
347 |
futures[i] = cachedThreadPool.submit(new CheckedRunnable() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
348 |
public void realRun() throws Throwable { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
349 |
threadsStarted.countDown(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
350 |
try { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
351 |
action.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
352 |
shouldThrow(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
353 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
354 |
catch (InterruptedException success) {} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
355 |
catch (Throwable fail) { threadUnexpectedException(fail); } |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
356 |
assertFalse(Thread.interrupted()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
357 |
done.countDown(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
358 |
}}); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
359 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
360 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
361 |
await(threadsStarted); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
362 |
assertEquals(n, done.getCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
363 |
for (Future<?> future : futures) // Interrupt all the tasks |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
364 |
future.cancel(true); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
365 |
await(done); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
366 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
367 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
368 |
/** |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
369 |
* interruptible operations throw InterruptedException when write locked and interrupted |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
370 |
*/ |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
371 |
public void testInterruptibleOperationsThrowInterruptedExceptionWriteLockedInterrupted() { |
35394 | 372 |
final StampedLock lock = new StampedLock(); |
373 |
long s = lock.writeLock(); |
|
374 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
375 |
Action[] interruptibleLockBlockingActions = { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
376 |
() -> lock.writeLockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
377 |
() -> lock.tryWriteLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
378 |
() -> lock.readLockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
379 |
() -> lock.tryReadLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
380 |
() -> lock.asWriteLock().lockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
381 |
() -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
382 |
() -> lock.asReadLock().lockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
383 |
() -> lock.asReadLock().tryLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
384 |
}; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
385 |
shuffle(interruptibleLockBlockingActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
386 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
387 |
assertThrowInterruptedExceptionWhenInterrupted(interruptibleLockBlockingActions); |
35394 | 388 |
} |
389 |
||
390 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
391 |
* interruptible operations throw InterruptedException when read locked and interrupted |
35394 | 392 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
393 |
public void testInterruptibleOperationsThrowInterruptedExceptionReadLockedInterrupted() { |
35394 | 394 |
final StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
395 |
long s = lock.readLock(); |
35394 | 396 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
397 |
Action[] interruptibleLockBlockingActions = { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
398 |
() -> lock.writeLockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
399 |
() -> lock.tryWriteLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
400 |
() -> lock.asWriteLock().lockInterruptibly(), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
401 |
() -> lock.asWriteLock().tryLock(Long.MAX_VALUE, DAYS), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
402 |
}; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
403 |
shuffle(interruptibleLockBlockingActions); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
404 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
405 |
assertThrowInterruptedExceptionWhenInterrupted(interruptibleLockBlockingActions); |
35394 | 406 |
} |
407 |
||
408 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
409 |
* Non-interruptible operations ignore and preserve interrupt status |
35394 | 410 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
411 |
public void testNonInterruptibleOperationsIgnoreInterrupts() { |
35394 | 412 |
final StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
413 |
Thread.currentThread().interrupt(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
414 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
415 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
416 |
long s = assertValid(lock, lock.readLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
417 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
418 |
s = assertValid(lock, lock.tryReadLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
419 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
420 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
421 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
422 |
lock.asReadLock().lock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
423 |
lock.asReadLock().unlock(); |
35394 | 424 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
425 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
426 |
long s = assertValid(lock, lock.writeLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
427 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
428 |
s = assertValid(lock, lock.tryWriteLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
429 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
430 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
431 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
432 |
lock.asWriteLock().lock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
433 |
lock.asWriteLock().unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
434 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
435 |
assertTrue(Thread.interrupted()); |
35394 | 436 |
} |
437 |
||
438 |
/** |
|
439 |
* tryWriteLock on an unlocked lock succeeds |
|
440 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
441 |
public void testTryWriteLock() { |
35394 | 442 |
final StampedLock lock = new StampedLock(); |
443 |
long s = lock.tryWriteLock(); |
|
444 |
assertTrue(s != 0L); |
|
445 |
assertTrue(lock.isWriteLocked()); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
446 |
assertEquals(0L, lock.tryWriteLock()); |
35394 | 447 |
releaseWriteLock(lock, s); |
448 |
} |
|
449 |
||
450 |
/** |
|
451 |
* tryWriteLock fails if locked |
|
452 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
453 |
public void testTryWriteLockWhenLocked() { |
35394 | 454 |
final StampedLock lock = new StampedLock(); |
455 |
long s = lock.writeLock(); |
|
456 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
457 |
public void realRun() { |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
458 |
assertEquals(0L, lock.tryWriteLock()); |
35394 | 459 |
}}); |
460 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
461 |
assertEquals(0L, lock.tryWriteLock()); |
35394 | 462 |
awaitTermination(t); |
463 |
releaseWriteLock(lock, s); |
|
464 |
} |
|
465 |
||
466 |
/** |
|
467 |
* tryReadLock fails if write-locked |
|
468 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
469 |
public void testTryReadLockWhenLocked() { |
35394 | 470 |
final StampedLock lock = new StampedLock(); |
471 |
long s = lock.writeLock(); |
|
472 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
473 |
public void realRun() { |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
474 |
assertEquals(0L, lock.tryReadLock()); |
35394 | 475 |
}}); |
476 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
477 |
assertEquals(0L, lock.tryReadLock()); |
35394 | 478 |
awaitTermination(t); |
479 |
releaseWriteLock(lock, s); |
|
480 |
} |
|
481 |
||
482 |
/** |
|
483 |
* Multiple threads can hold a read lock when not write-locked |
|
484 |
*/ |
|
485 |
public void testMultipleReadLocks() { |
|
486 |
final StampedLock lock = new StampedLock(); |
|
487 |
final long s = lock.readLock(); |
|
488 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
489 |
public void realRun() throws InterruptedException { |
|
490 |
long s2 = lock.tryReadLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
491 |
assertValid(lock, s2); |
35394 | 492 |
lock.unlockRead(s2); |
493 |
long s3 = lock.tryReadLock(LONG_DELAY_MS, MILLISECONDS); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
494 |
assertValid(lock, s3); |
35394 | 495 |
lock.unlockRead(s3); |
496 |
long s4 = lock.readLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
497 |
assertValid(lock, s4); |
35394 | 498 |
lock.unlockRead(s4); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
499 |
lock.asReadLock().lock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
500 |
lock.asReadLock().unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
501 |
lock.asReadLock().lockInterruptibly(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
502 |
lock.asReadLock().unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
503 |
lock.asReadLock().tryLock(Long.MIN_VALUE, DAYS); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
504 |
lock.asReadLock().unlock(); |
35394 | 505 |
}}); |
506 |
||
507 |
awaitTermination(t); |
|
508 |
lock.unlockRead(s); |
|
509 |
} |
|
510 |
||
511 |
/** |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
512 |
* writeLock() succeeds only after a reading thread unlocks |
35394 | 513 |
*/ |
514 |
public void testWriteAfterReadLock() throws InterruptedException { |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
515 |
final CountDownLatch aboutToLock = new CountDownLatch(1); |
35394 | 516 |
final StampedLock lock = new StampedLock(); |
517 |
long rs = lock.readLock(); |
|
518 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
519 |
public void realRun() { |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
520 |
aboutToLock.countDown(); |
35394 | 521 |
long s = lock.writeLock(); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
522 |
assertTrue(lock.isWriteLocked()); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
523 |
assertFalse(lock.isReadLocked()); |
35394 | 524 |
lock.unlockWrite(s); |
525 |
}}); |
|
526 |
||
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
527 |
await(aboutToLock); |
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
528 |
assertThreadBlocks(t, Thread.State.WAITING); |
35394 | 529 |
assertFalse(lock.isWriteLocked()); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
530 |
assertTrue(lock.isReadLocked()); |
35394 | 531 |
lock.unlockRead(rs); |
532 |
awaitTermination(t); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
533 |
assertUnlocked(lock); |
35394 | 534 |
} |
535 |
||
536 |
/** |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
537 |
* writeLock() succeeds only after reading threads unlock |
35394 | 538 |
*/ |
539 |
public void testWriteAfterMultipleReadLocks() { |
|
540 |
final StampedLock lock = new StampedLock(); |
|
541 |
long s = lock.readLock(); |
|
542 |
Thread t1 = newStartedThread(new CheckedRunnable() { |
|
543 |
public void realRun() { |
|
544 |
long rs = lock.readLock(); |
|
545 |
lock.unlockRead(rs); |
|
546 |
}}); |
|
547 |
||
548 |
awaitTermination(t1); |
|
549 |
||
550 |
Thread t2 = newStartedThread(new CheckedRunnable() { |
|
551 |
public void realRun() { |
|
552 |
long ws = lock.writeLock(); |
|
553 |
lock.unlockWrite(ws); |
|
554 |
}}); |
|
555 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
556 |
assertTrue(lock.isReadLocked()); |
35394 | 557 |
assertFalse(lock.isWriteLocked()); |
558 |
lock.unlockRead(s); |
|
559 |
awaitTermination(t2); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
560 |
assertUnlocked(lock); |
35394 | 561 |
} |
562 |
||
563 |
/** |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
564 |
* readLock() succeed only after a writing thread unlocks |
35394 | 565 |
*/ |
566 |
public void testReadAfterWriteLock() { |
|
567 |
final StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
568 |
final CountDownLatch threadsStarted = new CountDownLatch(2); |
35394 | 569 |
final long s = lock.writeLock(); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
570 |
final Runnable acquireReleaseReadLock = new CheckedRunnable() { |
35394 | 571 |
public void realRun() { |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
572 |
threadsStarted.countDown(); |
35394 | 573 |
long rs = lock.readLock(); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
574 |
assertTrue(lock.isReadLocked()); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
575 |
assertFalse(lock.isWriteLocked()); |
35394 | 576 |
lock.unlockRead(rs); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
577 |
}}; |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
578 |
Thread t1 = newStartedThread(acquireReleaseReadLock); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
579 |
Thread t2 = newStartedThread(acquireReleaseReadLock); |
35394 | 580 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
581 |
await(threadsStarted); |
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
582 |
assertThreadBlocks(t1, Thread.State.WAITING); |
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
583 |
assertThreadBlocks(t2, Thread.State.WAITING); |
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
584 |
assertTrue(lock.isWriteLocked()); |
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
585 |
assertFalse(lock.isReadLocked()); |
35394 | 586 |
releaseWriteLock(lock, s); |
587 |
awaitTermination(t1); |
|
588 |
awaitTermination(t2); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
589 |
assertUnlocked(lock); |
35394 | 590 |
} |
591 |
||
592 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
593 |
* tryReadLock succeeds if read locked but not write locked |
35394 | 594 |
*/ |
595 |
public void testTryLockWhenReadLocked() { |
|
596 |
final StampedLock lock = new StampedLock(); |
|
597 |
long s = lock.readLock(); |
|
598 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
599 |
public void realRun() { |
|
600 |
long rs = lock.tryReadLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
601 |
assertValid(lock, rs); |
35394 | 602 |
lock.unlockRead(rs); |
603 |
}}); |
|
604 |
||
605 |
awaitTermination(t); |
|
606 |
lock.unlockRead(s); |
|
607 |
} |
|
608 |
||
609 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
610 |
* tryWriteLock fails when read locked |
35394 | 611 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
612 |
public void testTryWriteLockWhenReadLocked() { |
35394 | 613 |
final StampedLock lock = new StampedLock(); |
614 |
long s = lock.readLock(); |
|
615 |
Thread t = newStartedThread(new CheckedRunnable() { |
|
616 |
public void realRun() { |
|
48048
f55cdd83e303
8191069: Miscellaneous changes imported from jsr166 CVS 2017-12
dl
parents:
47343
diff
changeset
|
617 |
assertEquals(0L, lock.tryWriteLock()); |
35394 | 618 |
}}); |
619 |
||
620 |
awaitTermination(t); |
|
621 |
lock.unlockRead(s); |
|
622 |
} |
|
623 |
||
624 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
625 |
* timed lock operations time out if lock not available |
35394 | 626 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
627 |
public void testTimedLock_Timeout() throws Exception { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
628 |
ArrayList<Future<?>> futures = new ArrayList<>(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
629 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
630 |
// Write locked |
35394 | 631 |
final StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
632 |
long stamp = lock.writeLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
633 |
assertEquals(0L, lock.tryReadLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
634 |
assertEquals(0L, lock.tryReadLock(Long.MIN_VALUE, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
635 |
assertFalse(lock.asReadLock().tryLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
636 |
assertFalse(lock.asReadLock().tryLock(Long.MIN_VALUE, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
637 |
assertEquals(0L, lock.tryWriteLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
638 |
assertEquals(0L, lock.tryWriteLock(Long.MIN_VALUE, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
639 |
assertFalse(lock.asWriteLock().tryLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
640 |
assertFalse(lock.asWriteLock().tryLock(Long.MIN_VALUE, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
641 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
642 |
futures.add(cachedThreadPool.submit(new CheckedRunnable() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
643 |
public void realRun() throws InterruptedException { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
644 |
long startTime = System.nanoTime(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
645 |
assertEquals(0L, lock.tryWriteLock(timeoutMillis(), MILLISECONDS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
646 |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
647 |
}})); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
648 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
649 |
futures.add(cachedThreadPool.submit(new CheckedRunnable() { |
35394 | 650 |
public void realRun() throws InterruptedException { |
651 |
long startTime = System.nanoTime(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
652 |
assertEquals(0L, lock.tryReadLock(timeoutMillis(), MILLISECONDS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
653 |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
654 |
}})); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
655 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
656 |
// Read locked |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
657 |
final StampedLock lock2 = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
658 |
long stamp2 = lock2.readLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
659 |
assertEquals(0L, lock2.tryWriteLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
660 |
assertEquals(0L, lock2.tryWriteLock(Long.MIN_VALUE, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
661 |
assertFalse(lock2.asWriteLock().tryLock(0L, DAYS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
662 |
assertFalse(lock2.asWriteLock().tryLock(Long.MIN_VALUE, DAYS)); |
35394 | 663 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
664 |
futures.add(cachedThreadPool.submit(new CheckedRunnable() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
665 |
public void realRun() throws InterruptedException { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
666 |
long startTime = System.nanoTime(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
667 |
assertEquals(0L, lock2.tryWriteLock(timeoutMillis(), MILLISECONDS)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
668 |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
669 |
}})); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
670 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
671 |
for (Future<?> future : futures) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
672 |
assertNull(future.get()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
673 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
674 |
releaseWriteLock(lock, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
675 |
releaseReadLock(lock2, stamp2); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
676 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
677 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
678 |
/** |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
679 |
* writeLockInterruptibly succeeds if unlocked |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
680 |
*/ |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
681 |
public void testWriteLockInterruptibly() throws InterruptedException { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
682 |
final StampedLock lock = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
683 |
long s = lock.writeLockInterruptibly(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
684 |
assertTrue(lock.isWriteLocked()); |
35394 | 685 |
releaseWriteLock(lock, s); |
686 |
} |
|
687 |
||
688 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
689 |
* readLockInterruptibly succeeds if lock free |
35394 | 690 |
*/ |
691 |
public void testReadLockInterruptibly() throws InterruptedException { |
|
692 |
final StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
693 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
694 |
long s = assertValid(lock, lock.readLockInterruptibly()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
695 |
assertTrue(lock.isReadLocked()); |
35394 | 696 |
lock.unlockRead(s); |
697 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
698 |
lock.asReadLock().lockInterruptibly(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
699 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
700 |
lock.asReadLock().unlock(); |
35394 | 701 |
} |
702 |
||
703 |
/** |
|
704 |
* A serialized lock deserializes as unlocked |
|
705 |
*/ |
|
706 |
public void testSerialization() { |
|
707 |
StampedLock lock = new StampedLock(); |
|
708 |
lock.writeLock(); |
|
709 |
StampedLock clone = serialClone(lock); |
|
710 |
assertTrue(lock.isWriteLocked()); |
|
711 |
assertFalse(clone.isWriteLocked()); |
|
712 |
long s = clone.writeLock(); |
|
713 |
assertTrue(clone.isWriteLocked()); |
|
714 |
clone.unlockWrite(s); |
|
715 |
assertFalse(clone.isWriteLocked()); |
|
716 |
} |
|
717 |
||
718 |
/** |
|
719 |
* toString indicates current lock state |
|
720 |
*/ |
|
721 |
public void testToString() { |
|
722 |
StampedLock lock = new StampedLock(); |
|
723 |
assertTrue(lock.toString().contains("Unlocked")); |
|
724 |
long s = lock.writeLock(); |
|
725 |
assertTrue(lock.toString().contains("Write-locked")); |
|
726 |
lock.unlockWrite(s); |
|
727 |
s = lock.readLock(); |
|
728 |
assertTrue(lock.toString().contains("Read-locks")); |
|
729 |
} |
|
730 |
||
731 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
732 |
* tryOptimisticRead succeeds and validates if unlocked, fails if |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
733 |
* exclusively locked |
35394 | 734 |
*/ |
735 |
public void testValidateOptimistic() throws InterruptedException { |
|
736 |
StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
737 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
738 |
assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
739 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
740 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
741 |
long s = assertValid(lock, writeLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
742 |
assertEquals(0L, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
743 |
releaseWriteLock(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
744 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
745 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
746 |
for (Function<StampedLock, Long> readLocker : readLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
747 |
long s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
748 |
long p = assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
749 |
releaseReadLock(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
750 |
assertTrue(lock.validate(p)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
751 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
752 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
753 |
assertValid(lock, lock.tryOptimisticRead()); |
35394 | 754 |
} |
755 |
||
756 |
/** |
|
757 |
* tryOptimisticRead stamp does not validate if a write lock intervenes |
|
758 |
*/ |
|
759 |
public void testValidateOptimisticWriteLocked() { |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
760 |
final StampedLock lock = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
761 |
final long p = assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
762 |
final long s = assertValid(lock, lock.writeLock()); |
35394 | 763 |
assertFalse(lock.validate(p)); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
764 |
assertEquals(0L, lock.tryOptimisticRead()); |
35394 | 765 |
assertTrue(lock.validate(s)); |
766 |
lock.unlockWrite(s); |
|
767 |
} |
|
768 |
||
769 |
/** |
|
770 |
* tryOptimisticRead stamp does not validate if a write lock |
|
771 |
* intervenes in another thread |
|
772 |
*/ |
|
773 |
public void testValidateOptimisticWriteLocked2() |
|
774 |
throws InterruptedException { |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
775 |
final CountDownLatch locked = new CountDownLatch(1); |
35394 | 776 |
final StampedLock lock = new StampedLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
777 |
final long p = assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
778 |
|
35394 | 779 |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
780 |
public void realRun() throws InterruptedException { |
|
781 |
lock.writeLockInterruptibly(); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
782 |
locked.countDown(); |
35394 | 783 |
lock.writeLockInterruptibly(); |
784 |
}}); |
|
785 |
||
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
44039
diff
changeset
|
786 |
await(locked); |
35394 | 787 |
assertFalse(lock.validate(p)); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
788 |
assertEquals(0L, lock.tryOptimisticRead()); |
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
789 |
assertThreadBlocks(t, Thread.State.WAITING); |
35394 | 790 |
t.interrupt(); |
791 |
awaitTermination(t); |
|
44039
058585425bb7
8173909: Miscellaneous changes imported from jsr166 CVS 2017-03
dl
parents:
42322
diff
changeset
|
792 |
assertTrue(lock.isWriteLocked()); |
35394 | 793 |
} |
794 |
||
795 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
796 |
* tryConvertToOptimisticRead succeeds and validates if successfully locked |
35394 | 797 |
*/ |
798 |
public void testTryConvertToOptimisticRead() throws InterruptedException { |
|
799 |
StampedLock lock = new StampedLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
800 |
long s, p, q; |
39722 | 801 |
assertEquals(0L, lock.tryConvertToOptimisticRead(0L)); |
802 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
803 |
s = assertValid(lock, lock.tryOptimisticRead()); |
39722 | 804 |
assertEquals(s, lock.tryConvertToOptimisticRead(s)); |
805 |
assertTrue(lock.validate(s)); |
|
806 |
||
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
807 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
808 |
s = assertValid(lock, writeLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
809 |
p = assertValid(lock, lock.tryConvertToOptimisticRead(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
810 |
assertFalse(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
811 |
assertTrue(lock.validate(p)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
812 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
813 |
} |
39722 | 814 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
815 |
for (Function<StampedLock, Long> readLocker : readLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
816 |
s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
817 |
q = assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
818 |
assertEquals(q, lock.tryConvertToOptimisticRead(q)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
819 |
assertTrue(lock.validate(q)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
820 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
821 |
p = assertValid(lock, lock.tryConvertToOptimisticRead(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
822 |
assertTrue(lock.validate(p)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
823 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
824 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
825 |
assertEquals(q, lock.tryConvertToOptimisticRead(q)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
826 |
assertTrue(lock.validate(q)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
827 |
} |
35394 | 828 |
} |
829 |
||
830 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
831 |
* tryConvertToReadLock succeeds for valid stamps |
35394 | 832 |
*/ |
833 |
public void testTryConvertToReadLock() throws InterruptedException { |
|
834 |
StampedLock lock = new StampedLock(); |
|
835 |
long s, p; |
|
39722 | 836 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
837 |
assertEquals(0L, lock.tryConvertToReadLock(0L)); |
39722 | 838 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
839 |
s = assertValid(lock, lock.tryOptimisticRead()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
840 |
p = assertValid(lock, lock.tryConvertToReadLock(s)); |
39722 | 841 |
assertTrue(lock.isReadLocked()); |
842 |
assertEquals(1, lock.getReadLockCount()); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
843 |
assertTrue(lock.validate(s)); |
35394 | 844 |
lock.unlockRead(p); |
39722 | 845 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
846 |
s = assertValid(lock, lock.tryOptimisticRead()); |
39722 | 847 |
lock.readLock(); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
848 |
p = assertValid(lock, lock.tryConvertToReadLock(s)); |
39722 | 849 |
assertTrue(lock.isReadLocked()); |
850 |
assertEquals(2, lock.getReadLockCount()); |
|
851 |
lock.unlockRead(p); |
|
852 |
lock.unlockRead(p); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
853 |
assertUnlocked(lock); |
39722 | 854 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
855 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
856 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
857 |
s = assertValid(lock, writeLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
858 |
p = assertValid(lock, lock.tryConvertToReadLock(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
859 |
assertFalse(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
860 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
861 |
assertEquals(1, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
862 |
readUnlocker.accept(lock, p); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
863 |
} |
39722 | 864 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
865 |
for (Function<StampedLock, Long> readLocker : readLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
866 |
s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
867 |
assertEquals(s, lock.tryConvertToReadLock(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
868 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
869 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
870 |
assertEquals(1, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
871 |
readUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
872 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
873 |
} |
35394 | 874 |
} |
875 |
||
876 |
/** |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
877 |
* tryConvertToWriteLock succeeds if lock available; fails if multiply read locked |
35394 | 878 |
*/ |
879 |
public void testTryConvertToWriteLock() throws InterruptedException { |
|
880 |
StampedLock lock = new StampedLock(); |
|
881 |
long s, p; |
|
39722 | 882 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
883 |
assertEquals(0L, lock.tryConvertToWriteLock(0L)); |
39722 | 884 |
|
35394 | 885 |
assertTrue((s = lock.tryOptimisticRead()) != 0L); |
886 |
assertTrue((p = lock.tryConvertToWriteLock(s)) != 0L); |
|
39722 | 887 |
assertTrue(lock.isWriteLocked()); |
35394 | 888 |
lock.unlockWrite(p); |
39722 | 889 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
890 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
891 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
892 |
s = assertValid(lock, writeLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
893 |
assertEquals(s, lock.tryConvertToWriteLock(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
894 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
895 |
assertTrue(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
896 |
writeUnlocker.accept(lock, s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
897 |
} |
39722 | 898 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
899 |
for (Function<StampedLock, Long> readLocker : readLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
900 |
s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
901 |
p = assertValid(lock, lock.tryConvertToWriteLock(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
902 |
assertFalse(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
903 |
assertTrue(lock.validate(p)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
904 |
assertTrue(lock.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
905 |
writeUnlocker.accept(lock, p); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
906 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
907 |
} |
39722 | 908 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
909 |
// failure if multiply read locked |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
910 |
for (Function<StampedLock, Long> readLocker : readLockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
911 |
s = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
912 |
p = assertValid(lock, readLocker.apply(lock)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
913 |
assertEquals(0L, lock.tryConvertToWriteLock(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
914 |
assertTrue(lock.validate(s)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
915 |
assertTrue(lock.validate(p)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
916 |
assertEquals(2, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
917 |
lock.unlock(p); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
918 |
lock.unlock(s); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
919 |
assertUnlocked(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
920 |
} |
35394 | 921 |
} |
922 |
||
923 |
/** |
|
924 |
* asWriteLock can be locked and unlocked |
|
925 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
926 |
public void testAsWriteLock() throws Throwable { |
35394 | 927 |
StampedLock sl = new StampedLock(); |
928 |
Lock lock = sl.asWriteLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
929 |
for (Action locker : lockLockers(lock)) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
930 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
931 |
assertTrue(sl.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
932 |
assertFalse(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
933 |
assertFalse(lock.tryLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
934 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
935 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
936 |
} |
35394 | 937 |
} |
938 |
||
939 |
/** |
|
940 |
* asReadLock can be locked and unlocked |
|
941 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
942 |
public void testAsReadLock() throws Throwable { |
35394 | 943 |
StampedLock sl = new StampedLock(); |
944 |
Lock lock = sl.asReadLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
945 |
for (Action locker : lockLockers(lock)) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
946 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
947 |
assertTrue(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
948 |
assertFalse(sl.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
949 |
assertEquals(1, sl.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
950 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
951 |
assertTrue(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
952 |
assertEquals(2, sl.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
953 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
954 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
955 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
956 |
} |
35394 | 957 |
} |
958 |
||
959 |
/** |
|
960 |
* asReadWriteLock.writeLock can be locked and unlocked |
|
961 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
962 |
public void testAsReadWriteLockWriteLock() throws Throwable { |
35394 | 963 |
StampedLock sl = new StampedLock(); |
964 |
Lock lock = sl.asReadWriteLock().writeLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
965 |
for (Action locker : lockLockers(lock)) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
966 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
967 |
assertTrue(sl.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
968 |
assertFalse(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
969 |
assertFalse(lock.tryLock()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
970 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
971 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
972 |
} |
35394 | 973 |
} |
974 |
||
975 |
/** |
|
976 |
* asReadWriteLock.readLock can be locked and unlocked |
|
977 |
*/ |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
978 |
public void testAsReadWriteLockReadLock() throws Throwable { |
35394 | 979 |
StampedLock sl = new StampedLock(); |
980 |
Lock lock = sl.asReadWriteLock().readLock(); |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
981 |
for (Action locker : lockLockers(lock)) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
982 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
983 |
assertTrue(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
984 |
assertFalse(sl.isWriteLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
985 |
assertEquals(1, sl.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
986 |
locker.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
987 |
assertTrue(sl.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
988 |
assertEquals(2, sl.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
989 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
990 |
lock.unlock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
991 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
992 |
} |
35394 | 993 |
} |
994 |
||
39722 | 995 |
/** |
996 |
* Lock.newCondition throws UnsupportedOperationException |
|
997 |
*/ |
|
998 |
public void testLockViewsDoNotSupportConditions() { |
|
999 |
StampedLock sl = new StampedLock(); |
|
1000 |
assertThrows(UnsupportedOperationException.class, |
|
1001 |
() -> sl.asWriteLock().newCondition(), |
|
1002 |
() -> sl.asReadLock().newCondition(), |
|
1003 |
() -> sl.asReadWriteLock().writeLock().newCondition(), |
|
1004 |
() -> sl.asReadWriteLock().readLock().newCondition()); |
|
1005 |
} |
|
1006 |
||
1007 |
/** |
|
1008 |
* Passing optimistic read stamps to unlock operations result in |
|
1009 |
* IllegalMonitorStateException |
|
1010 |
*/ |
|
1011 |
public void testCannotUnlockOptimisticReadStamps() { |
|
54686
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1012 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1013 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1014 |
long stamp = assertValid(sl, sl.tryOptimisticRead()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1015 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1016 |
() -> sl.unlockRead(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1017 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1018 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1019 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1020 |
long stamp = sl.tryOptimisticRead(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1021 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1022 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1023 |
} |
39722 | 1024 |
|
54686
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1025 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1026 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1027 |
long stamp = sl.tryOptimisticRead(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1028 |
sl.writeLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1029 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1030 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1031 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1032 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1033 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1034 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1035 |
long stamp = assertValid(sl, sl.tryOptimisticRead()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1036 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1037 |
() -> sl.unlockRead(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1038 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1039 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1040 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1041 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1042 |
long stamp = assertValid(sl, sl.tryOptimisticRead()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1043 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1044 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1045 |
} |
39722 | 1046 |
|
54686
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1047 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1048 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1049 |
long stamp = sl.tryConvertToOptimisticRead(sl.writeLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1050 |
assertValid(sl, stamp); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1051 |
sl.writeLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1052 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1053 |
() -> sl.unlockWrite(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1054 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1055 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1056 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1057 |
long stamp = sl.tryConvertToOptimisticRead(sl.writeLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1058 |
sl.writeLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1059 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1060 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1061 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1062 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1063 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1064 |
long stamp = sl.tryConvertToOptimisticRead(sl.writeLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1065 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1066 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1067 |
() -> sl.unlockRead(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1068 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1069 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1070 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1071 |
long stamp = sl.tryConvertToOptimisticRead(sl.writeLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1072 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1073 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1074 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1075 |
} |
39722 | 1076 |
|
54686
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1077 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1078 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1079 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1080 |
assertValid(sl, stamp); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1081 |
sl.writeLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1082 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1083 |
() -> sl.unlockWrite(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1084 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1085 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1086 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1087 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1088 |
sl.writeLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1089 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1090 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1091 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1092 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1093 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1094 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1095 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1096 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1097 |
() -> sl.unlockRead(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1098 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1099 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1100 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1101 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1102 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1103 |
assertValid(sl, stamp); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1104 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1105 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1106 |
() -> sl.unlockRead(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1107 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1108 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1109 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1110 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1111 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1112 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1113 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1114 |
} |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1115 |
{ |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1116 |
StampedLock sl = new StampedLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1117 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1118 |
long stamp = sl.tryConvertToOptimisticRead(sl.readLock()); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1119 |
sl.readLock(); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1120 |
assertThrows(IllegalMonitorStateException.class, |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1121 |
() -> sl.unlock(stamp)); |
09f09b4e7808
8219138: Miscellaneous changes imported from jsr166 CVS 2019-05
dl
parents:
48048
diff
changeset
|
1122 |
} |
39722 | 1123 |
} |
1124 |
||
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1125 |
static long writeLockInterruptiblyUninterrupted(StampedLock sl) { |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1126 |
try { return sl.writeLockInterruptibly(); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1127 |
catch (InterruptedException ex) { throw new AssertionError(ex); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1128 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1129 |
|
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1130 |
static long tryWriteLockUninterrupted(StampedLock sl, long time, TimeUnit unit) { |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1131 |
try { return sl.tryWriteLock(time, unit); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1132 |
catch (InterruptedException ex) { throw new AssertionError(ex); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1133 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1134 |
|
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1135 |
static long readLockInterruptiblyUninterrupted(StampedLock sl) { |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1136 |
try { return sl.readLockInterruptibly(); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1137 |
catch (InterruptedException ex) { throw new AssertionError(ex); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1138 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1139 |
|
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1140 |
static long tryReadLockUninterrupted(StampedLock sl, long time, TimeUnit unit) { |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1141 |
try { return sl.tryReadLock(time, unit); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1142 |
catch (InterruptedException ex) { throw new AssertionError(ex); } |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1143 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1144 |
|
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1145 |
/** |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1146 |
* Invalid stamps result in IllegalMonitorStateException |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1147 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1148 |
public void testInvalidStampsThrowIllegalMonitorStateException() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1149 |
final StampedLock sl = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1150 |
|
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1151 |
assertThrows(IllegalMonitorStateException.class, |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1152 |
() -> sl.unlockWrite(0L), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1153 |
() -> sl.unlockRead(0L), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1154 |
() -> sl.unlock(0L)); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1155 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1156 |
final long optimisticStamp = sl.tryOptimisticRead(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1157 |
final long readStamp = sl.readLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1158 |
sl.unlockRead(readStamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1159 |
final long writeStamp = sl.writeLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1160 |
sl.unlockWrite(writeStamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1161 |
assertTrue(optimisticStamp != 0L && readStamp != 0L && writeStamp != 0L); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1162 |
final long[] noLongerValidStamps = { optimisticStamp, readStamp, writeStamp }; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1163 |
final Runnable assertNoLongerValidStampsThrow = () -> { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1164 |
for (long noLongerValidStamp : noLongerValidStamps) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1165 |
assertThrows(IllegalMonitorStateException.class, |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1166 |
() -> sl.unlockWrite(noLongerValidStamp), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1167 |
() -> sl.unlockRead(noLongerValidStamp), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1168 |
() -> sl.unlock(noLongerValidStamp)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1169 |
}; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1170 |
assertNoLongerValidStampsThrow.run(); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1171 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1172 |
for (Function<StampedLock, Long> readLocker : readLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1173 |
for (BiConsumer<StampedLock, Long> readUnlocker : readUnlockers()) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1174 |
final long stamp = readLocker.apply(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1175 |
assertValid(sl, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1176 |
assertNoLongerValidStampsThrow.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1177 |
assertThrows(IllegalMonitorStateException.class, |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1178 |
() -> sl.unlockWrite(stamp), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1179 |
() -> sl.unlockRead(sl.tryOptimisticRead()), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1180 |
() -> sl.unlockRead(0L)); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1181 |
readUnlocker.accept(sl, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1182 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1183 |
assertNoLongerValidStampsThrow.run(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1184 |
} |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1185 |
|
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1186 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1187 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1188 |
final long stamp = writeLocker.apply(sl); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1189 |
assertValid(sl, stamp); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1190 |
assertNoLongerValidStampsThrow.run(); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1191 |
assertThrows(IllegalMonitorStateException.class, |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1192 |
() -> sl.unlockRead(stamp), |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1193 |
() -> sl.unlockWrite(0L)); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1194 |
writeUnlocker.accept(sl, stamp); |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1195 |
assertUnlocked(sl); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1196 |
assertNoLongerValidStampsThrow.run(); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1197 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1198 |
} |
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1199 |
|
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1200 |
/** |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1201 |
* Read locks can be very deeply nested |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1202 |
*/ |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1203 |
public void testDeeplyNestedReadLocks() { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1204 |
final StampedLock lock = new StampedLock(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1205 |
final int depth = 300; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1206 |
final long[] stamps = new long[depth]; |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1207 |
final List<Function<StampedLock, Long>> readLockers = readLockers(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1208 |
final List<BiConsumer<StampedLock, Long>> readUnlockers = readUnlockers(); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1209 |
for (int i = 0; i < depth; i++) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1210 |
Function<StampedLock, Long> readLocker |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1211 |
= readLockers.get(i % readLockers.size()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1212 |
long stamp = readLocker.apply(lock); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1213 |
assertEquals(i + 1, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1214 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1215 |
stamps[i] = stamp; |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1216 |
} |
40278
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1217 |
for (int i = 0; i < depth; i++) { |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1218 |
BiConsumer<StampedLock, Long> readUnlocker |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1219 |
= readUnlockers.get(i % readUnlockers.size()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1220 |
assertEquals(depth - i, lock.getReadLockCount()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1221 |
assertTrue(lock.isReadLocked()); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1222 |
readUnlocker.accept(lock, stamps[depth - 1 - i]); |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1223 |
} |
8801563939d0
8163210: java/util/concurrent/tck/JSR166TestCase.java testWriteAfterReadLock(StampedLockTest): timed out waiting for thread to terminate
dl
parents:
39780
diff
changeset
|
1224 |
assertUnlocked(lock); |
39780
18618975fbb6
8161608: StampedLock should use storeStoreFence when acquiring write lock
dl
parents:
39722
diff
changeset
|
1225 |
} |
47307
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1226 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1227 |
/** |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1228 |
* Stamped locks are not reentrant. |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1229 |
*/ |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1230 |
public void testNonReentrant() throws InterruptedException { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1231 |
final StampedLock lock = new StampedLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1232 |
long stamp; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1233 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1234 |
stamp = lock.writeLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1235 |
assertValid(lock, stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1236 |
assertEquals(0L, lock.tryWriteLock(0L, DAYS)); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1237 |
assertEquals(0L, lock.tryReadLock(0L, DAYS)); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1238 |
assertValid(lock, stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1239 |
lock.unlockWrite(stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1240 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1241 |
stamp = lock.tryWriteLock(1L, DAYS); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1242 |
assertEquals(0L, lock.tryWriteLock(0L, DAYS)); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1243 |
assertValid(lock, stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1244 |
lock.unlockWrite(stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1245 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1246 |
stamp = lock.readLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1247 |
assertEquals(0L, lock.tryWriteLock(0L, DAYS)); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1248 |
assertValid(lock, stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1249 |
lock.unlockRead(stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1250 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1251 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1252 |
/** |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1253 |
* """StampedLocks have no notion of ownership. Locks acquired in |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1254 |
* one thread can be released or converted in another.""" |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1255 |
*/ |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1256 |
public void testNoOwnership() throws Throwable { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1257 |
ArrayList<Future<?>> futures = new ArrayList<>(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1258 |
for (Function<StampedLock, Long> writeLocker : writeLockers()) |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1259 |
for (BiConsumer<StampedLock, Long> writeUnlocker : writeUnlockers()) { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1260 |
StampedLock lock = new StampedLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1261 |
long stamp = writeLocker.apply(lock); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1262 |
futures.add(cachedThreadPool.submit(new CheckedRunnable() { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1263 |
public void realRun() { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1264 |
writeUnlocker.accept(lock, stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1265 |
assertUnlocked(lock); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1266 |
assertFalse(lock.validate(stamp)); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1267 |
}})); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1268 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1269 |
for (Future<?> future : futures) |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1270 |
assertNull(future.get()); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1271 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1272 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1273 |
/** Tries out sample usage code from StampedLock javadoc. */ |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1274 |
public void testSampleUsage() throws Throwable { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1275 |
class Point { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1276 |
private double x, y; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1277 |
private final StampedLock sl = new StampedLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1278 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1279 |
void move(double deltaX, double deltaY) { // an exclusively locked method |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1280 |
long stamp = sl.writeLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1281 |
try { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1282 |
x += deltaX; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1283 |
y += deltaY; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1284 |
} finally { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1285 |
sl.unlockWrite(stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1286 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1287 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1288 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1289 |
double distanceFromOrigin() { // A read-only method |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1290 |
double currentX, currentY; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1291 |
long stamp = sl.tryOptimisticRead(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1292 |
do { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1293 |
if (stamp == 0L) |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1294 |
stamp = sl.readLock(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1295 |
try { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1296 |
// possibly racy reads |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1297 |
currentX = x; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1298 |
currentY = y; |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1299 |
} finally { |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1300 |
stamp = sl.tryConvertToOptimisticRead(stamp); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1301 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1302 |
} while (stamp == 0); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1303 |
return Math.hypot(currentX, currentY); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1304 |
} |
47343 | 1305 |
|
1306 |
double distanceFromOrigin2() { |
|
1307 |
long stamp = sl.tryOptimisticRead(); |
|
1308 |
try { |
|
1309 |
retryHoldingLock: |
|
1310 |
for (;; stamp = sl.readLock()) { |
|
1311 |
if (stamp == 0L) |
|
1312 |
continue retryHoldingLock; |
|
1313 |
// possibly racy reads |
|
1314 |
double currentX = x; |
|
1315 |
double currentY = y; |
|
1316 |
if (!sl.validate(stamp)) |
|
1317 |
continue retryHoldingLock; |
|
1318 |
return Math.hypot(currentX, currentY); |
|
1319 |
} |
|
1320 |
} finally { |
|
1321 |
if (StampedLock.isReadLockStamp(stamp)) |
|
1322 |
sl.unlockRead(stamp); |
|
1323 |
} |
|
1324 |
} |
|
1325 |
||
1326 |
void moveIfAtOrigin(double newX, double newY) { |
|
1327 |
long stamp = sl.readLock(); |
|
1328 |
try { |
|
1329 |
while (x == 0.0 && y == 0.0) { |
|
1330 |
long ws = sl.tryConvertToWriteLock(stamp); |
|
1331 |
if (ws != 0L) { |
|
1332 |
stamp = ws; |
|
1333 |
x = newX; |
|
1334 |
y = newY; |
|
1335 |
return; |
|
1336 |
} |
|
1337 |
else { |
|
1338 |
sl.unlockRead(stamp); |
|
1339 |
stamp = sl.writeLock(); |
|
1340 |
} |
|
1341 |
} |
|
1342 |
} finally { |
|
1343 |
sl.unlock(stamp); |
|
1344 |
} |
|
1345 |
} |
|
47307
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1346 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1347 |
|
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1348 |
Point p = new Point(); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1349 |
p.move(3.0, 4.0); |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1350 |
assertEquals(5.0, p.distanceFromOrigin()); |
47343 | 1351 |
p.moveIfAtOrigin(5.0, 12.0); |
1352 |
assertEquals(5.0, p.distanceFromOrigin2()); |
|
1353 |
} |
|
1354 |
||
1355 |
/** |
|
1356 |
* Stamp inspection methods work as expected, and do not inspect |
|
1357 |
* the state of the lock itself. |
|
1358 |
*/ |
|
1359 |
public void testStampStateInspectionMethods() { |
|
1360 |
StampedLock lock = new StampedLock(); |
|
1361 |
||
1362 |
assertFalse(isWriteLockStamp(0L)); |
|
1363 |
assertFalse(isReadLockStamp(0L)); |
|
1364 |
assertFalse(isLockStamp(0L)); |
|
1365 |
assertFalse(isOptimisticReadStamp(0L)); |
|
1366 |
||
1367 |
{ |
|
1368 |
long stamp = lock.writeLock(); |
|
1369 |
for (int i = 0; i < 2; i++) { |
|
1370 |
assertTrue(isWriteLockStamp(stamp)); |
|
1371 |
assertFalse(isReadLockStamp(stamp)); |
|
1372 |
assertTrue(isLockStamp(stamp)); |
|
1373 |
assertFalse(isOptimisticReadStamp(stamp)); |
|
1374 |
if (i == 0) |
|
1375 |
lock.unlockWrite(stamp); |
|
1376 |
} |
|
1377 |
} |
|
1378 |
||
1379 |
{ |
|
1380 |
long stamp = lock.readLock(); |
|
1381 |
for (int i = 0; i < 2; i++) { |
|
1382 |
assertFalse(isWriteLockStamp(stamp)); |
|
1383 |
assertTrue(isReadLockStamp(stamp)); |
|
1384 |
assertTrue(isLockStamp(stamp)); |
|
1385 |
assertFalse(isOptimisticReadStamp(stamp)); |
|
1386 |
if (i == 0) |
|
1387 |
lock.unlockRead(stamp); |
|
1388 |
} |
|
1389 |
} |
|
1390 |
||
1391 |
{ |
|
1392 |
long optimisticStamp = lock.tryOptimisticRead(); |
|
1393 |
long readStamp = lock.tryConvertToReadLock(optimisticStamp); |
|
1394 |
long writeStamp = lock.tryConvertToWriteLock(readStamp); |
|
1395 |
for (int i = 0; i < 2; i++) { |
|
1396 |
assertFalse(isWriteLockStamp(optimisticStamp)); |
|
1397 |
assertFalse(isReadLockStamp(optimisticStamp)); |
|
1398 |
assertFalse(isLockStamp(optimisticStamp)); |
|
1399 |
assertTrue(isOptimisticReadStamp(optimisticStamp)); |
|
1400 |
||
1401 |
assertFalse(isWriteLockStamp(readStamp)); |
|
1402 |
assertTrue(isReadLockStamp(readStamp)); |
|
1403 |
assertTrue(isLockStamp(readStamp)); |
|
1404 |
assertFalse(isOptimisticReadStamp(readStamp)); |
|
1405 |
||
1406 |
assertTrue(isWriteLockStamp(writeStamp)); |
|
1407 |
assertFalse(isReadLockStamp(writeStamp)); |
|
1408 |
assertTrue(isLockStamp(writeStamp)); |
|
1409 |
assertFalse(isOptimisticReadStamp(writeStamp)); |
|
1410 |
if (i == 0) |
|
1411 |
lock.unlockWrite(writeStamp); |
|
1412 |
} |
|
1413 |
} |
|
47307
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1414 |
} |
6864969a78ad
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
dl
parents:
47216
diff
changeset
|
1415 |
|
58893
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1416 |
/** |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1417 |
* Multiple threads repeatedly contend for the same lock. |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1418 |
*/ |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1419 |
public void testConcurrentAccess() throws Exception { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1420 |
final StampedLock sl = new StampedLock(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1421 |
final Lock wl = sl.asWriteLock(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1422 |
final Lock rl = sl.asReadLock(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1423 |
final long testDurationMillis = expensiveTests ? 1000 : 2; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1424 |
final int nTasks = ThreadLocalRandom.current().nextInt(1, 10); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1425 |
final AtomicBoolean done = new AtomicBoolean(false); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1426 |
final List<CompletableFuture> futures = new ArrayList<>(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1427 |
final List<Callable<Long>> stampedWriteLockers = List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1428 |
() -> sl.writeLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1429 |
() -> writeLockInterruptiblyUninterrupted(sl), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1430 |
() -> tryWriteLockUninterrupted(sl, LONG_DELAY_MS, MILLISECONDS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1431 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1432 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1433 |
do { stamp = sl.tryConvertToWriteLock(sl.tryOptimisticRead()); } |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1434 |
while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1435 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1436 |
}, |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1437 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1438 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1439 |
do { stamp = sl.tryWriteLock(); } while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1440 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1441 |
}, |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1442 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1443 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1444 |
do { stamp = sl.tryWriteLock(0L, DAYS); } while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1445 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1446 |
}); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1447 |
final List<Callable<Long>> stampedReadLockers = List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1448 |
() -> sl.readLock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1449 |
() -> readLockInterruptiblyUninterrupted(sl), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1450 |
() -> tryReadLockUninterrupted(sl, LONG_DELAY_MS, MILLISECONDS), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1451 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1452 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1453 |
do { stamp = sl.tryConvertToReadLock(sl.tryOptimisticRead()); } |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1454 |
while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1455 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1456 |
}, |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1457 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1458 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1459 |
do { stamp = sl.tryReadLock(); } while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1460 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1461 |
}, |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1462 |
() -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1463 |
long stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1464 |
do { stamp = sl.tryReadLock(0L, DAYS); } while (stamp == 0L); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1465 |
return stamp; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1466 |
}); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1467 |
final List<Consumer<Long>> stampedWriteUnlockers = List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1468 |
stamp -> sl.unlockWrite(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1469 |
stamp -> sl.unlock(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1470 |
stamp -> assertTrue(sl.tryUnlockWrite()), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1471 |
stamp -> wl.unlock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1472 |
stamp -> sl.tryConvertToOptimisticRead(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1473 |
final List<Consumer<Long>> stampedReadUnlockers = List.of( |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1474 |
stamp -> sl.unlockRead(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1475 |
stamp -> sl.unlock(stamp), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1476 |
stamp -> assertTrue(sl.tryUnlockRead()), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1477 |
stamp -> rl.unlock(), |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1478 |
stamp -> sl.tryConvertToOptimisticRead(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1479 |
final Action writer = () -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1480 |
// repeatedly acquires write lock |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1481 |
var locker = chooseRandomly(stampedWriteLockers); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1482 |
var unlocker = chooseRandomly(stampedWriteUnlockers); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1483 |
while (!done.getAcquire()) { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1484 |
long stamp = locker.call(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1485 |
try { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1486 |
assertTrue(isWriteLockStamp(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1487 |
assertTrue(sl.isWriteLocked()); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1488 |
assertFalse(isReadLockStamp(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1489 |
assertFalse(sl.isReadLocked()); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1490 |
assertEquals(0, sl.getReadLockCount()); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1491 |
assertTrue(sl.validate(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1492 |
} finally { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1493 |
unlocker.accept(stamp); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1494 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1495 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1496 |
}; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1497 |
final Action reader = () -> { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1498 |
// repeatedly acquires read lock |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1499 |
var locker = chooseRandomly(stampedReadLockers); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1500 |
var unlocker = chooseRandomly(stampedReadUnlockers); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1501 |
while (!done.getAcquire()) { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1502 |
long stamp = locker.call(); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1503 |
try { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1504 |
assertFalse(isWriteLockStamp(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1505 |
assertFalse(sl.isWriteLocked()); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1506 |
assertTrue(isReadLockStamp(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1507 |
assertTrue(sl.isReadLocked()); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1508 |
assertTrue(sl.getReadLockCount() > 0); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1509 |
assertTrue(sl.validate(stamp)); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1510 |
} finally { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1511 |
unlocker.accept(stamp); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1512 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1513 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1514 |
}; |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1515 |
for (int i = nTasks; i--> 0; ) { |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1516 |
Action task = chooseRandomly(writer, reader); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1517 |
futures.add(CompletableFuture.runAsync(checkedRunnable(task))); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1518 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1519 |
Thread.sleep(testDurationMillis); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1520 |
done.setRelease(true); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1521 |
for (var future : futures) |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1522 |
checkTimedGet(future, null); |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1523 |
} |
ec954ef6caf1
8231026: Miscellaneous changes imported from jsr166 CVS 2019-11
dl
parents:
54686
diff
changeset
|
1524 |
|
35394 | 1525 |
} |