12 |
|
import java.util.Arrays; |
13 |
|
import java.util.Collection; |
14 |
|
import java.util.HashSet; |
15 |
– |
import java.util.concurrent.ThreadLocalRandom; |
15 |
|
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer; |
16 |
|
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; |
17 |
|
|
1264 |
|
|
1265 |
|
// A synchronizer only offering a choice of failure modes |
1266 |
|
class Sync extends AbstractQueuedLongSynchronizer { |
1267 |
< |
boolean pleaseThrow; |
1267 |
> |
volatile boolean pleaseThrow; |
1268 |
|
@Override protected boolean tryAcquire(long ignored) { |
1269 |
|
if (pleaseThrow) throw ex; |
1270 |
|
return false; |
1286 |
|
final Thread thread = newStartedThread(new CheckedRunnable() { |
1287 |
|
public void realRun() { |
1288 |
|
try { |
1289 |
< |
if (ThreadLocalRandom.current().nextBoolean()) |
1289 |
> |
if (randomBoolean()) |
1290 |
|
s.acquire(1); |
1291 |
|
else |
1292 |
|
s.acquireShared(1); |