127 |
|
void acquire(Semaphore s) throws InterruptedException { |
128 |
|
assertTrue(s.tryAcquire(2 * LONG_DELAY_MS, MILLISECONDS)); |
129 |
|
} |
130 |
+ |
Thread.State parkedState() { return Thread.State.TIMED_WAITING; } |
131 |
|
}, |
132 |
|
tryAcquireTimedN { |
133 |
|
void acquire(Semaphore s, int permits) throws InterruptedException { |
134 |
|
assertTrue(s.tryAcquire(permits, 2 * LONG_DELAY_MS, MILLISECONDS)); |
135 |
|
} |
136 |
+ |
Thread.State parkedState() { return Thread.State.TIMED_WAITING; } |
137 |
|
}; |
138 |
|
|
139 |
|
// Intentionally meta-circular |
147 |
|
for (int i = 0; i < permits; i++) |
148 |
|
acquire(s); |
149 |
|
} |
150 |
+ |
Thread.State parkedState() { return Thread.State.WAITING; } |
151 |
|
} |
152 |
|
|
153 |
|
/** |
230 |
|
public void testInterruptible_tryAcquireTimedN_fair() { testInterruptible(true, AcquireMethod.tryAcquireTimedN); } |
231 |
|
public void testInterruptible(boolean fair, final AcquireMethod acquirer) { |
232 |
|
final PublicSemaphore s = new PublicSemaphore(0, fair); |
233 |
< |
final Semaphore pleaseInterrupt = new Semaphore(0, fair); |
233 |
> |
final java.util.concurrent.CyclicBarrier pleaseInterrupt |
234 |
> |
= new java.util.concurrent.CyclicBarrier(2); |
235 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
236 |
|
public void realRun() { |
237 |
|
// Interrupt before acquire |
240 |
|
acquirer.acquire(s); |
241 |
|
shouldThrow(); |
242 |
|
} catch (InterruptedException success) {} |
243 |
< |
|
240 |
< |
// Interrupt during acquire |
241 |
< |
try { |
242 |
< |
acquirer.acquire(s); |
243 |
< |
shouldThrow(); |
244 |
< |
} catch (InterruptedException success) {} |
243 |
> |
assertFalse(Thread.interrupted()); |
244 |
|
|
245 |
|
// Interrupt before acquire(N) |
246 |
|
Thread.currentThread().interrupt(); |
248 |
|
acquirer.acquire(s, 3); |
249 |
|
shouldThrow(); |
250 |
|
} catch (InterruptedException success) {} |
251 |
+ |
assertFalse(Thread.interrupted()); |
252 |
|
|
253 |
< |
pleaseInterrupt.release(); |
253 |
> |
// Interrupt during acquire |
254 |
> |
await(pleaseInterrupt); |
255 |
> |
try { |
256 |
> |
acquirer.acquire(s); |
257 |
> |
shouldThrow(); |
258 |
> |
} catch (InterruptedException success) {} |
259 |
> |
assertFalse(Thread.interrupted()); |
260 |
|
|
261 |
|
// Interrupt during acquire(N) |
262 |
+ |
await(pleaseInterrupt); |
263 |
|
try { |
264 |
|
acquirer.acquire(s, 3); |
265 |
|
shouldThrow(); |
266 |
|
} catch (InterruptedException success) {} |
267 |
+ |
assertFalse(Thread.interrupted()); |
268 |
|
}}); |
269 |
|
|
270 |
< |
waitForQueuedThread(s, t); |
271 |
< |
t.interrupt(); |
272 |
< |
await(pleaseInterrupt); |
273 |
< |
waitForQueuedThread(s, t); |
274 |
< |
t.interrupt(); |
270 |
> |
for (int n = 2; n-->0; ) { |
271 |
> |
await(pleaseInterrupt); |
272 |
> |
assertThreadBlocks(t, acquirer.parkedState()); |
273 |
> |
t.interrupt(); |
274 |
> |
} |
275 |
> |
|
276 |
|
awaitTermination(t); |
277 |
|
} |
278 |
|
|