equal
deleted
inserted
replaced
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 6207928 6328220 6378321 6625723 |
26 * @bug 6207928 6328220 6378321 6625723 |
27 * @summary Recursive lock invariant sanity checks |
27 * @summary Recursive lock invariant sanity checks |
|
28 * @library /lib/testlibrary/ |
28 * @author Martin Buchholz |
29 * @author Martin Buchholz |
29 */ |
30 */ |
|
31 |
|
32 import static java.util.concurrent.TimeUnit.MILLISECONDS; |
30 |
33 |
31 import java.io.ByteArrayInputStream; |
34 import java.io.ByteArrayInputStream; |
32 import java.io.ByteArrayOutputStream; |
35 import java.io.ByteArrayOutputStream; |
33 import java.io.IOException; |
36 import java.io.IOException; |
34 import java.io.InputStream; |
37 import java.io.InputStream; |
40 import java.util.concurrent.Executors; |
43 import java.util.concurrent.Executors; |
41 import java.util.concurrent.TimeUnit; |
44 import java.util.concurrent.TimeUnit; |
42 import java.util.concurrent.locks.Lock; |
45 import java.util.concurrent.locks.Lock; |
43 import java.util.concurrent.locks.ReentrantLock; |
46 import java.util.concurrent.locks.ReentrantLock; |
44 import java.util.concurrent.locks.ReentrantReadWriteLock; |
47 import java.util.concurrent.locks.ReentrantReadWriteLock; |
|
48 import jdk.testlibrary.Utils; |
45 |
49 |
46 // I am the Cownt, and I lahve to cownt. |
50 // I am the Cownt, and I lahve to cownt. |
47 public class Count { |
51 public class Count { |
|
52 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000); |
48 final Random rnd = new Random(); |
53 final Random rnd = new Random(); |
49 |
54 |
50 void lock(Lock lock) { |
55 void lock(Lock lock) { |
51 try { |
56 try { |
52 switch (rnd.nextInt(4)) { |
57 switch (rnd.nextInt(4)) { |
100 new F(){void f(){rwl.readLock().unlock();}}, |
105 new F(){void f(){rwl.readLock().unlock();}}, |
101 new F(){void f(){rwl.writeLock().unlock();}}); |
106 new F(){void f(){rwl.writeLock().unlock();}}); |
102 barrier.await(); |
107 barrier.await(); |
103 } catch (Throwable t) { unexpected(t); }}});} |
108 } catch (Throwable t) { unexpected(t); }}});} |
104 es.shutdown(); |
109 es.shutdown(); |
105 check(es.awaitTermination(10L, TimeUnit.SECONDS)); |
110 check(es.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
106 } |
111 } |
107 |
112 |
108 void testReentrantLocks(final boolean fair, |
113 void testReentrantLocks(final boolean fair, |
109 final boolean serialClone) throws Throwable { |
114 final boolean serialClone) throws Throwable { |
110 final ReentrantLock rl = serialClone ? |
115 final ReentrantLock rl = serialClone ? |