13 |
|
import java.util.Arrays; |
14 |
|
import java.util.Collection; |
15 |
|
import java.util.HashSet; |
16 |
– |
import java.util.concurrent.ThreadLocalRandom; |
16 |
|
import java.util.concurrent.locks.AbstractQueuedSynchronizer; |
17 |
|
import java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject; |
18 |
|
|
1282 |
|
try { |
1283 |
|
s.acquireInterruptibly(1); |
1284 |
|
shouldThrow(); |
1285 |
< |
} catch (InterruptedException expected) {} |
1285 |
> |
} catch (InterruptedException success) {} |
1286 |
|
}; |
1287 |
|
for (int i = 0; i < 2; i++) { |
1288 |
|
Thread thread = new Thread(failedAcquire); |
1315 |
|
|
1316 |
|
// A synchronizer only offering a choice of failure modes |
1317 |
|
class Sync extends AbstractQueuedSynchronizer { |
1318 |
< |
boolean pleaseThrow; |
1318 |
> |
volatile boolean pleaseThrow; |
1319 |
|
@Override protected boolean tryAcquire(int ignored) { |
1320 |
|
if (pleaseThrow) throw ex; |
1321 |
|
return false; |
1337 |
|
final Thread thread = newStartedThread(new CheckedRunnable() { |
1338 |
|
public void realRun() { |
1339 |
|
try { |
1340 |
< |
if (ThreadLocalRandom.current().nextBoolean()) |
1340 |
> |
if (randomBoolean()) |
1341 |
|
s.acquire(1); |
1342 |
|
else |
1343 |
|
s.acquireShared(1); |