20 |
|
import junit.framework.Test; |
21 |
|
import junit.framework.TestSuite; |
22 |
|
|
23 |
+ |
@SuppressWarnings("WaitNotInLoop") // we implement spurious-wakeup freedom |
24 |
|
public class ReentrantLockTest extends JSR166TestCase { |
25 |
|
public static void main(String[] args) { |
26 |
|
main(suite(), args); |
886 |
|
public void testAwaitUninterruptibly_fair() { testAwaitUninterruptibly(true); } |
887 |
|
public void testAwaitUninterruptibly(boolean fair) { |
888 |
|
final ReentrantLock lock = new ReentrantLock(fair); |
889 |
< |
final Condition c = lock.newCondition(); |
889 |
> |
final Condition condition = lock.newCondition(); |
890 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(2); |
891 |
|
|
892 |
|
Thread t1 = newStartedThread(new CheckedRunnable() { |
895 |
|
lock.lock(); |
896 |
|
pleaseInterrupt.countDown(); |
897 |
|
Thread.currentThread().interrupt(); |
898 |
< |
c.awaitUninterruptibly(); |
898 |
> |
condition.awaitUninterruptibly(); |
899 |
|
assertTrue(Thread.interrupted()); |
900 |
|
lock.unlock(); |
901 |
|
}}); |
905 |
|
// Interrupt during awaitUninterruptibly |
906 |
|
lock.lock(); |
907 |
|
pleaseInterrupt.countDown(); |
908 |
< |
c.awaitUninterruptibly(); |
908 |
> |
condition.awaitUninterruptibly(); |
909 |
|
assertTrue(Thread.interrupted()); |
910 |
|
lock.unlock(); |
911 |
|
}}); |
912 |
|
|
913 |
|
await(pleaseInterrupt); |
914 |
+ |
t2.interrupt(); |
915 |
|
lock.lock(); |
916 |
|
lock.unlock(); |
917 |
< |
t2.interrupt(); |
918 |
< |
|
917 |
< |
assertThreadStaysAlive(t1); |
918 |
< |
assertTrue(t2.isAlive()); |
917 |
> |
assertThreadBlocks(t1, Thread.State.WAITING); |
918 |
> |
assertThreadBlocks(t2, Thread.State.WAITING); |
919 |
|
|
920 |
|
lock.lock(); |
921 |
< |
c.signalAll(); |
921 |
> |
condition.signalAll(); |
922 |
|
lock.unlock(); |
923 |
|
|
924 |
|
awaitTermination(t1); |