1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
10 |
|
import junit.framework.*; |
11 |
|
import java.util.*; |
12 |
|
import java.util.concurrent.*; |
13 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
|
import java.util.concurrent.locks.*; |
15 |
|
import java.io.*; |
16 |
|
|
17 |
|
public class AbstractQueuedSynchronizerTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(AbstractQueuedSynchronizerTest.class); |
34 |
|
public boolean isHeldExclusively() { return getState() == 1; } |
35 |
|
|
36 |
|
public boolean tryAcquire(int acquires) { |
37 |
< |
assertTrue(acquires == 1); |
37 |
> |
assertEquals(1, acquires); |
38 |
|
return compareAndSetState(0, 1); |
39 |
|
} |
40 |
|
|
44 |
|
return true; |
45 |
|
} |
46 |
|
|
47 |
< |
public AbstractQueuedSynchronizer.ConditionObject newCondition() { return new AbstractQueuedSynchronizer.ConditionObject(); } |
47 |
> |
public AbstractQueuedSynchronizer.ConditionObject newCondition() { |
48 |
> |
return new AbstractQueuedSynchronizer.ConditionObject(); |
49 |
> |
} |
50 |
|
|
51 |
|
} |
52 |
|
|
58 |
|
public boolean isSignalled() { return getState() != 0; } |
59 |
|
|
60 |
|
public int tryAcquireShared(int ignore) { |
61 |
< |
return isSignalled()? 1 : -1; |
61 |
> |
return isSignalled() ? 1 : -1; |
62 |
|
} |
63 |
|
|
64 |
|
public boolean tryReleaseShared(int ignore) { |
131 |
|
assertFalse(sync.hasQueuedThreads()); |
132 |
|
sync.acquire(1); |
133 |
|
t1.start(); |
134 |
< |
Thread.sleep(SHORT_DELAY_MS); |
134 |
> |
delay(SHORT_DELAY_MS); |
135 |
|
assertTrue(sync.hasQueuedThreads()); |
136 |
|
t2.start(); |
137 |
< |
Thread.sleep(SHORT_DELAY_MS); |
137 |
> |
delay(SHORT_DELAY_MS); |
138 |
|
assertTrue(sync.hasQueuedThreads()); |
139 |
|
t1.interrupt(); |
140 |
< |
Thread.sleep(SHORT_DELAY_MS); |
140 |
> |
delay(SHORT_DELAY_MS); |
141 |
|
assertTrue(sync.hasQueuedThreads()); |
142 |
|
sync.release(1); |
143 |
< |
Thread.sleep(SHORT_DELAY_MS); |
143 |
> |
delay(SHORT_DELAY_MS); |
144 |
|
assertFalse(sync.hasQueuedThreads()); |
145 |
|
t1.join(); |
146 |
|
t2.join(); |
168 |
|
assertFalse(sync.isQueued(t2)); |
169 |
|
sync.acquire(1); |
170 |
|
t1.start(); |
171 |
< |
Thread.sleep(SHORT_DELAY_MS); |
171 |
> |
delay(SHORT_DELAY_MS); |
172 |
|
assertTrue(sync.isQueued(t1)); |
173 |
|
t2.start(); |
174 |
< |
Thread.sleep(SHORT_DELAY_MS); |
174 |
> |
delay(SHORT_DELAY_MS); |
175 |
|
assertTrue(sync.isQueued(t1)); |
176 |
|
assertTrue(sync.isQueued(t2)); |
177 |
|
t1.interrupt(); |
178 |
< |
Thread.sleep(SHORT_DELAY_MS); |
178 |
> |
delay(SHORT_DELAY_MS); |
179 |
|
assertFalse(sync.isQueued(t1)); |
180 |
|
assertTrue(sync.isQueued(t2)); |
181 |
|
sync.release(1); |
182 |
< |
Thread.sleep(SHORT_DELAY_MS); |
182 |
> |
delay(SHORT_DELAY_MS); |
183 |
|
assertFalse(sync.isQueued(t1)); |
184 |
< |
Thread.sleep(SHORT_DELAY_MS); |
184 |
> |
delay(SHORT_DELAY_MS); |
185 |
|
assertFalse(sync.isQueued(t2)); |
186 |
|
t1.join(); |
187 |
|
t2.join(); |
197 |
|
assertNull(sync.getFirstQueuedThread()); |
198 |
|
sync.acquire(1); |
199 |
|
t1.start(); |
200 |
< |
Thread.sleep(SHORT_DELAY_MS); |
200 |
> |
delay(SHORT_DELAY_MS); |
201 |
|
assertEquals(t1, sync.getFirstQueuedThread()); |
202 |
|
t2.start(); |
203 |
< |
Thread.sleep(SHORT_DELAY_MS); |
203 |
> |
delay(SHORT_DELAY_MS); |
204 |
|
assertEquals(t1, sync.getFirstQueuedThread()); |
205 |
|
t1.interrupt(); |
206 |
< |
Thread.sleep(SHORT_DELAY_MS); |
207 |
< |
Thread.sleep(SHORT_DELAY_MS); |
206 |
> |
delay(SHORT_DELAY_MS); |
207 |
> |
delay(SHORT_DELAY_MS); |
208 |
|
assertEquals(t2, sync.getFirstQueuedThread()); |
209 |
|
sync.release(1); |
210 |
< |
Thread.sleep(SHORT_DELAY_MS); |
210 |
> |
delay(SHORT_DELAY_MS); |
211 |
|
assertNull(sync.getFirstQueuedThread()); |
212 |
|
t1.join(); |
213 |
|
t2.join(); |
224 |
|
assertFalse(sync.hasContended()); |
225 |
|
sync.acquire(1); |
226 |
|
t1.start(); |
227 |
< |
Thread.sleep(SHORT_DELAY_MS); |
227 |
> |
delay(SHORT_DELAY_MS); |
228 |
|
assertTrue(sync.hasContended()); |
229 |
|
t2.start(); |
230 |
< |
Thread.sleep(SHORT_DELAY_MS); |
230 |
> |
delay(SHORT_DELAY_MS); |
231 |
|
assertTrue(sync.hasContended()); |
232 |
|
t1.interrupt(); |
233 |
< |
Thread.sleep(SHORT_DELAY_MS); |
233 |
> |
delay(SHORT_DELAY_MS); |
234 |
|
assertTrue(sync.hasContended()); |
235 |
|
sync.release(1); |
236 |
< |
Thread.sleep(SHORT_DELAY_MS); |
236 |
> |
delay(SHORT_DELAY_MS); |
237 |
|
assertTrue(sync.hasContended()); |
238 |
|
t1.join(); |
239 |
|
t2.join(); |
250 |
|
sync.acquire(1); |
251 |
|
assertTrue(sync.getQueuedThreads().isEmpty()); |
252 |
|
t1.start(); |
253 |
< |
Thread.sleep(SHORT_DELAY_MS); |
253 |
> |
delay(SHORT_DELAY_MS); |
254 |
|
assertTrue(sync.getQueuedThreads().contains(t1)); |
255 |
|
t2.start(); |
256 |
< |
Thread.sleep(SHORT_DELAY_MS); |
256 |
> |
delay(SHORT_DELAY_MS); |
257 |
|
assertTrue(sync.getQueuedThreads().contains(t1)); |
258 |
|
assertTrue(sync.getQueuedThreads().contains(t2)); |
259 |
|
t1.interrupt(); |
260 |
< |
Thread.sleep(SHORT_DELAY_MS); |
260 |
> |
delay(SHORT_DELAY_MS); |
261 |
|
assertFalse(sync.getQueuedThreads().contains(t1)); |
262 |
|
assertTrue(sync.getQueuedThreads().contains(t2)); |
263 |
|
sync.release(1); |
264 |
< |
Thread.sleep(SHORT_DELAY_MS); |
264 |
> |
delay(SHORT_DELAY_MS); |
265 |
|
assertTrue(sync.getQueuedThreads().isEmpty()); |
266 |
|
t1.join(); |
267 |
|
t2.join(); |
278 |
|
sync.acquire(1); |
279 |
|
assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); |
280 |
|
t1.start(); |
281 |
< |
Thread.sleep(SHORT_DELAY_MS); |
281 |
> |
delay(SHORT_DELAY_MS); |
282 |
|
assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); |
283 |
|
t2.start(); |
284 |
< |
Thread.sleep(SHORT_DELAY_MS); |
284 |
> |
delay(SHORT_DELAY_MS); |
285 |
|
assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); |
286 |
|
assertTrue(sync.getExclusiveQueuedThreads().contains(t2)); |
287 |
|
t1.interrupt(); |
288 |
< |
Thread.sleep(SHORT_DELAY_MS); |
288 |
> |
delay(SHORT_DELAY_MS); |
289 |
|
assertFalse(sync.getExclusiveQueuedThreads().contains(t1)); |
290 |
|
assertTrue(sync.getExclusiveQueuedThreads().contains(t2)); |
291 |
|
sync.release(1); |
292 |
< |
Thread.sleep(SHORT_DELAY_MS); |
292 |
> |
delay(SHORT_DELAY_MS); |
293 |
|
assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); |
294 |
|
t1.join(); |
295 |
|
t2.join(); |
306 |
|
sync.acquire(1); |
307 |
|
assertTrue(sync.getSharedQueuedThreads().isEmpty()); |
308 |
|
t1.start(); |
309 |
< |
Thread.sleep(SHORT_DELAY_MS); |
309 |
> |
delay(SHORT_DELAY_MS); |
310 |
|
assertTrue(sync.getSharedQueuedThreads().isEmpty()); |
311 |
|
t2.start(); |
312 |
< |
Thread.sleep(SHORT_DELAY_MS); |
312 |
> |
delay(SHORT_DELAY_MS); |
313 |
|
assertTrue(sync.getSharedQueuedThreads().isEmpty()); |
314 |
|
t1.interrupt(); |
315 |
< |
Thread.sleep(SHORT_DELAY_MS); |
315 |
> |
delay(SHORT_DELAY_MS); |
316 |
|
assertTrue(sync.getSharedQueuedThreads().isEmpty()); |
317 |
|
sync.release(1); |
318 |
< |
Thread.sleep(SHORT_DELAY_MS); |
318 |
> |
delay(SHORT_DELAY_MS); |
319 |
|
assertTrue(sync.getSharedQueuedThreads().isEmpty()); |
320 |
|
t1.join(); |
321 |
|
t2.join(); |
329 |
|
sync.acquire(1); |
330 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
331 |
|
public void realRun() throws InterruptedException { |
332 |
< |
sync.tryAcquireNanos(1, MEDIUM_DELAY_MS * 1000 * 1000); |
332 |
> |
sync.tryAcquireNanos(1, MILLISECONDS.toNanos(MEDIUM_DELAY_MS)); |
333 |
|
}}); |
334 |
|
|
335 |
|
t.start(); |
336 |
+ |
delay(SHORT_DELAY_MS); |
337 |
|
t.interrupt(); |
338 |
|
t.join(); |
339 |
|
} |
347 |
|
sync.acquire(1); |
348 |
|
Thread t = new Thread(new CheckedRunnable() { |
349 |
|
public void realRun() { |
350 |
< |
threadAssertFalse(sync.tryAcquire(1)); |
350 |
> |
assertFalse(sync.tryAcquire(1)); |
351 |
|
}}); |
352 |
|
|
353 |
|
t.start(); |
363 |
|
sync.acquire(1); |
364 |
|
Thread t = new Thread(new CheckedRunnable() { |
365 |
|
public void realRun() throws InterruptedException { |
366 |
< |
threadAssertFalse(sync.tryAcquireNanos(1, 1000 * 1000)); |
366 |
> |
long nanos = MILLISECONDS.toNanos(SHORT_DELAY_MS); |
367 |
> |
assertFalse(sync.tryAcquireNanos(1, nanos)); |
368 |
|
}}); |
369 |
|
|
370 |
|
t.start(); |
385 |
|
Thread t = new Thread(new CheckedRunnable() { |
386 |
|
public void realRun() throws InterruptedException { |
387 |
|
sync.acquire(1); |
388 |
< |
Thread.sleep(SMALL_DELAY_MS); |
388 |
> |
delay(SMALL_DELAY_MS); |
389 |
|
sync.release(1); |
390 |
|
}}); |
391 |
|
|
392 |
|
t.start(); |
393 |
< |
Thread.sleep(SHORT_DELAY_MS); |
393 |
> |
delay(SHORT_DELAY_MS); |
394 |
|
assertTrue(sync.isHeldExclusively()); |
395 |
|
t.join(); |
396 |
|
assertFalse(sync.isHeldExclusively()); |
406 |
|
Thread t = new Thread(new InterruptedSyncRunnable(sync)); |
407 |
|
|
408 |
|
t.start(); |
409 |
< |
Thread.sleep(SHORT_DELAY_MS); |
409 |
> |
delay(SHORT_DELAY_MS); |
410 |
|
t.interrupt(); |
411 |
< |
Thread.sleep(SHORT_DELAY_MS); |
411 |
> |
delay(SHORT_DELAY_MS); |
412 |
|
sync.release(1); |
413 |
|
t.join(); |
414 |
|
} |
421 |
|
sync.acquireInterruptibly(1); |
422 |
|
Thread t = new Thread(new InterruptedSyncRunnable(sync)); |
423 |
|
t.start(); |
424 |
+ |
delay(SHORT_DELAY_MS); |
425 |
|
t.interrupt(); |
426 |
|
assertTrue(sync.isHeldExclusively()); |
427 |
|
t.join(); |
475 |
|
} |
476 |
|
|
477 |
|
/** |
478 |
< |
* Timed await without a signal times out |
478 |
> |
* Timed await without a signal times out |
479 |
|
*/ |
480 |
|
public void testAwait_Timeout() throws InterruptedException { |
481 |
|
final Mutex sync = new Mutex(); |
482 |
|
final AbstractQueuedSynchronizer.ConditionObject c = sync.newCondition(); |
483 |
|
sync.acquire(1); |
484 |
< |
assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
484 |
> |
assertFalse(c.await(SHORT_DELAY_MS, MILLISECONDS)); |
485 |
|
sync.release(1); |
486 |
|
} |
487 |
|
|
511 |
|
}}); |
512 |
|
|
513 |
|
t.start(); |
514 |
< |
Thread.sleep(SHORT_DELAY_MS); |
514 |
> |
delay(SHORT_DELAY_MS); |
515 |
|
sync.acquire(1); |
516 |
|
c.signal(); |
517 |
|
sync.release(1); |
644 |
|
Thread t = new Thread(new CheckedRunnable() { |
645 |
|
public void realRun() throws InterruptedException { |
646 |
|
sync.acquire(1); |
647 |
< |
threadAssertFalse(sync.hasWaiters(c)); |
648 |
< |
threadAssertEquals(0, sync.getWaitQueueLength(c)); |
647 |
> |
assertFalse(sync.hasWaiters(c)); |
648 |
> |
assertEquals(0, sync.getWaitQueueLength(c)); |
649 |
|
c.await(); |
650 |
|
sync.release(1); |
651 |
|
}}); |
652 |
|
|
653 |
|
t.start(); |
654 |
< |
Thread.sleep(SHORT_DELAY_MS); |
654 |
> |
delay(SHORT_DELAY_MS); |
655 |
|
sync.acquire(1); |
656 |
|
assertTrue(sync.hasWaiters(c)); |
657 |
|
assertEquals(1, sync.getWaitQueueLength(c)); |
658 |
|
c.signal(); |
659 |
|
sync.release(1); |
660 |
< |
Thread.sleep(SHORT_DELAY_MS); |
660 |
> |
delay(SHORT_DELAY_MS); |
661 |
|
sync.acquire(1); |
662 |
|
assertFalse(sync.hasWaiters(c)); |
663 |
|
assertEquals(0, sync.getWaitQueueLength(c)); |
675 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
676 |
|
public void realRun() throws InterruptedException { |
677 |
|
sync.acquire(1); |
678 |
< |
threadAssertFalse(sync.hasWaiters(c)); |
679 |
< |
threadAssertEquals(0, sync.getWaitQueueLength(c)); |
678 |
> |
assertFalse(sync.hasWaiters(c)); |
679 |
> |
assertEquals(0, sync.getWaitQueueLength(c)); |
680 |
|
c.await(); |
681 |
|
sync.release(1); |
682 |
|
}}); |
684 |
|
Thread t2 = new Thread(new CheckedRunnable() { |
685 |
|
public void realRun() throws InterruptedException { |
686 |
|
sync.acquire(1); |
687 |
< |
threadAssertTrue(sync.hasWaiters(c)); |
688 |
< |
threadAssertEquals(1, sync.getWaitQueueLength(c)); |
687 |
> |
assertTrue(sync.hasWaiters(c)); |
688 |
> |
assertEquals(1, sync.getWaitQueueLength(c)); |
689 |
|
c.await(); |
690 |
|
sync.release(1); |
691 |
|
}}); |
692 |
|
|
693 |
|
t1.start(); |
694 |
< |
Thread.sleep(SHORT_DELAY_MS); |
694 |
> |
delay(SHORT_DELAY_MS); |
695 |
|
t2.start(); |
696 |
< |
Thread.sleep(SHORT_DELAY_MS); |
696 |
> |
delay(SHORT_DELAY_MS); |
697 |
|
sync.acquire(1); |
698 |
|
assertTrue(sync.hasWaiters(c)); |
699 |
|
assertEquals(2, sync.getWaitQueueLength(c)); |
700 |
|
c.signalAll(); |
701 |
|
sync.release(1); |
702 |
< |
Thread.sleep(SHORT_DELAY_MS); |
702 |
> |
delay(SHORT_DELAY_MS); |
703 |
|
sync.acquire(1); |
704 |
|
assertFalse(sync.hasWaiters(c)); |
705 |
|
assertEquals(0, sync.getWaitQueueLength(c)); |
719 |
|
Thread t1 = new Thread(new CheckedRunnable() { |
720 |
|
public void realRun() throws InterruptedException { |
721 |
|
sync.acquire(1); |
722 |
< |
threadAssertTrue(sync.getWaitingThreads(c).isEmpty()); |
722 |
> |
assertTrue(sync.getWaitingThreads(c).isEmpty()); |
723 |
|
c.await(); |
724 |
|
sync.release(1); |
725 |
|
}}); |
727 |
|
Thread t2 = new Thread(new CheckedRunnable() { |
728 |
|
public void realRun() throws InterruptedException { |
729 |
|
sync.acquire(1); |
730 |
< |
threadAssertFalse(sync.getWaitingThreads(c).isEmpty()); |
730 |
> |
assertFalse(sync.getWaitingThreads(c).isEmpty()); |
731 |
|
c.await(); |
732 |
|
sync.release(1); |
733 |
|
}}); |
736 |
|
assertTrue(sync.getWaitingThreads(c).isEmpty()); |
737 |
|
sync.release(1); |
738 |
|
t1.start(); |
739 |
< |
Thread.sleep(SHORT_DELAY_MS); |
739 |
> |
delay(SHORT_DELAY_MS); |
740 |
|
t2.start(); |
741 |
< |
Thread.sleep(SHORT_DELAY_MS); |
741 |
> |
delay(SHORT_DELAY_MS); |
742 |
|
sync.acquire(1); |
743 |
|
assertTrue(sync.hasWaiters(c)); |
744 |
|
assertTrue(sync.getWaitingThreads(c).contains(t1)); |
745 |
|
assertTrue(sync.getWaitingThreads(c).contains(t2)); |
746 |
|
c.signalAll(); |
747 |
|
sync.release(1); |
748 |
< |
Thread.sleep(SHORT_DELAY_MS); |
748 |
> |
delay(SHORT_DELAY_MS); |
749 |
|
sync.acquire(1); |
750 |
|
assertFalse(sync.hasWaiters(c)); |
751 |
|
assertTrue(sync.getWaitingThreads(c).isEmpty()); |
772 |
|
}}); |
773 |
|
|
774 |
|
t.start(); |
775 |
< |
Thread.sleep(SHORT_DELAY_MS); |
775 |
> |
delay(SHORT_DELAY_MS); |
776 |
|
t.interrupt(); |
777 |
|
sync.acquire(1); |
778 |
|
c.signal(); |
791 |
|
public void realRun() throws InterruptedException { |
792 |
|
sync.acquire(1); |
793 |
|
c.await(); |
788 |
– |
sync.release(1); |
794 |
|
}}); |
795 |
|
|
796 |
|
t.start(); |
797 |
< |
Thread.sleep(SHORT_DELAY_MS); |
797 |
> |
delay(SHORT_DELAY_MS); |
798 |
|
t.interrupt(); |
799 |
|
t.join(SHORT_DELAY_MS); |
800 |
|
assertFalse(t.isAlive()); |
809 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
810 |
|
public void realRun() throws InterruptedException { |
811 |
|
sync.acquire(1); |
812 |
< |
c.awaitNanos(1000 * 1000 * 1000); // 1 sec |
808 |
< |
sync.release(1); |
812 |
> |
c.awaitNanos(MILLISECONDS.toNanos(LONG_DELAY_MS)); |
813 |
|
}}); |
814 |
|
|
815 |
|
t.start(); |
816 |
< |
Thread.sleep(SHORT_DELAY_MS); |
816 |
> |
delay(SHORT_DELAY_MS); |
817 |
|
t.interrupt(); |
818 |
|
t.join(SHORT_DELAY_MS); |
819 |
|
assertFalse(t.isAlive()); |
830 |
|
sync.acquire(1); |
831 |
|
java.util.Date d = new java.util.Date(); |
832 |
|
c.awaitUntil(new java.util.Date(d.getTime() + 10000)); |
829 |
– |
sync.release(1); |
833 |
|
}}); |
834 |
|
|
835 |
|
t.start(); |
836 |
< |
Thread.sleep(SHORT_DELAY_MS); |
836 |
> |
delay(SHORT_DELAY_MS); |
837 |
|
t.interrupt(); |
838 |
|
t.join(SHORT_DELAY_MS); |
839 |
|
assertFalse(t.isAlive()); |
861 |
|
|
862 |
|
t1.start(); |
863 |
|
t2.start(); |
864 |
< |
Thread.sleep(SHORT_DELAY_MS); |
864 |
> |
delay(SHORT_DELAY_MS); |
865 |
|
sync.acquire(1); |
866 |
|
c.signalAll(); |
867 |
|
sync.release(1); |
934 |
|
|
935 |
|
Thread t = new Thread(new CheckedRunnable() { |
936 |
|
public void realRun() throws InterruptedException { |
937 |
< |
threadAssertFalse(l.isSignalled()); |
937 |
> |
assertFalse(l.isSignalled()); |
938 |
|
l.acquireSharedInterruptibly(0); |
939 |
< |
threadAssertTrue(l.isSignalled()); |
939 |
> |
assertTrue(l.isSignalled()); |
940 |
|
}}); |
941 |
|
|
942 |
|
t.start(); |
943 |
|
assertFalse(l.isSignalled()); |
944 |
< |
Thread.sleep(SHORT_DELAY_MS); |
944 |
> |
delay(SHORT_DELAY_MS); |
945 |
|
l.releaseShared(0); |
946 |
|
assertTrue(l.isSignalled()); |
947 |
|
t.join(); |
951 |
|
/** |
952 |
|
* acquireSharedTimed returns after release |
953 |
|
*/ |
954 |
< |
public void testAsquireSharedTimed() throws InterruptedException { |
954 |
> |
public void testAcquireSharedTimed() throws InterruptedException { |
955 |
|
final BooleanLatch l = new BooleanLatch(); |
956 |
|
|
957 |
|
Thread t = new Thread(new CheckedRunnable() { |
958 |
|
public void realRun() throws InterruptedException { |
959 |
< |
threadAssertFalse(l.isSignalled()); |
960 |
< |
threadAssertTrue(l.tryAcquireSharedNanos(0, MEDIUM_DELAY_MS* 1000 * 1000)); |
961 |
< |
threadAssertTrue(l.isSignalled()); |
959 |
> |
assertFalse(l.isSignalled()); |
960 |
> |
long nanos = MILLISECONDS.toNanos(MEDIUM_DELAY_MS); |
961 |
> |
assertTrue(l.tryAcquireSharedNanos(0, nanos)); |
962 |
> |
assertTrue(l.isSignalled()); |
963 |
|
}}); |
964 |
|
|
965 |
|
t.start(); |
966 |
|
assertFalse(l.isSignalled()); |
967 |
< |
Thread.sleep(SHORT_DELAY_MS); |
967 |
> |
delay(SHORT_DELAY_MS); |
968 |
|
l.releaseShared(0); |
969 |
|
assertTrue(l.isSignalled()); |
970 |
|
t.join(); |
977 |
|
final BooleanLatch l = new BooleanLatch(); |
978 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
979 |
|
public void realRun() throws InterruptedException { |
980 |
< |
threadAssertFalse(l.isSignalled()); |
980 |
> |
assertFalse(l.isSignalled()); |
981 |
|
l.acquireSharedInterruptibly(0); |
982 |
|
}}); |
983 |
|
|
994 |
|
final BooleanLatch l = new BooleanLatch(); |
995 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
996 |
|
public void realRun() throws InterruptedException { |
997 |
< |
threadAssertFalse(l.isSignalled()); |
998 |
< |
l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000); |
997 |
> |
assertFalse(l.isSignalled()); |
998 |
> |
long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); |
999 |
> |
l.tryAcquireSharedNanos(0, nanos); |
1000 |
|
}}); |
1001 |
|
|
1002 |
|
t.start(); |
1003 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1003 |
> |
delay(SHORT_DELAY_MS); |
1004 |
|
assertFalse(l.isSignalled()); |
1005 |
|
t.interrupt(); |
1006 |
|
t.join(); |
1013 |
|
final BooleanLatch l = new BooleanLatch(); |
1014 |
|
Thread t = new Thread(new CheckedRunnable() { |
1015 |
|
public void realRun() throws InterruptedException { |
1016 |
< |
threadAssertFalse(l.isSignalled()); |
1017 |
< |
threadAssertFalse(l.tryAcquireSharedNanos(0, SMALL_DELAY_MS* 1000 * 1000)); |
1016 |
> |
assertFalse(l.isSignalled()); |
1017 |
> |
long nanos = MILLISECONDS.toNanos(SMALL_DELAY_MS); |
1018 |
> |
assertFalse(l.tryAcquireSharedNanos(0, nanos)); |
1019 |
|
}}); |
1020 |
|
|
1021 |
|
t.start(); |
1022 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1022 |
> |
delay(SHORT_DELAY_MS); |
1023 |
|
assertFalse(l.isSignalled()); |
1024 |
|
t.join(); |
1025 |
|
} |