186 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
187 |
|
public void realRun() { |
188 |
|
pleaseInterrupt.countDown(); |
189 |
< |
do { |
189 |
> |
for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) { |
190 |
|
parkMethod.park(); |
191 |
< |
// park may return spuriously |
192 |
< |
} while (! Thread.interrupted()); |
191 |
> |
if (Thread.interrupted()) |
192 |
> |
return; |
193 |
> |
} |
194 |
> |
fail("too many consecutive spurious wakeups?"); |
195 |
|
}}); |
196 |
|
|
197 |
|
await(pleaseInterrupt); |
223 |
|
} |
224 |
|
public void testParkAfterInterrupt(final ParkMethod parkMethod) { |
225 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
224 |
– |
final AtomicBoolean pleasePark = new AtomicBoolean(false); |
226 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
227 |
|
public void realRun() throws Exception { |
228 |
|
pleaseInterrupt.countDown(); |
229 |
< |
while (!pleasePark.get()) |
229 |
> |
while (!Thread.currentThread().isInterrupted()) |
230 |
|
Thread.yield(); |
230 |
– |
assertTrue(Thread.currentThread().isInterrupted()); |
231 |
|
parkMethod.park(); |
232 |
< |
assertTrue(Thread.currentThread().isInterrupted()); |
232 |
> |
assertTrue(Thread.interrupted()); |
233 |
|
}}); |
234 |
|
|
235 |
|
await(pleaseInterrupt); |
236 |
|
t.interrupt(); |
237 |
– |
pleasePark.set(true); |
237 |
|
awaitTermination(t); |
238 |
|
} |
239 |
|
|
258 |
|
for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) { |
259 |
|
long startTime = System.nanoTime(); |
260 |
|
parkMethod.park(timeoutMillis()); |
262 |
– |
// park may return spuriously |
261 |
|
if (millisElapsedSince(startTime) >= timeoutMillis()) |
262 |
|
return; |
263 |
|
} |
295 |
|
public void realRun() { |
296 |
|
Thread t = Thread.currentThread(); |
297 |
|
started.countDown(); |
298 |
< |
do { |
298 |
> |
for (int tries = MAX_SPURIOUS_WAKEUPS; tries-->0; ) { |
299 |
|
assertNull(LockSupport.getBlocker(t)); |
300 |
|
parkMethod.park(); |
301 |
|
assertNull(LockSupport.getBlocker(t)); |
302 |
< |
// park may return spuriously |
303 |
< |
} while (! Thread.interrupted()); |
302 |
> |
if (Thread.interrupted()) |
303 |
> |
return; |
304 |
> |
} |
305 |
> |
fail("too many consecutive spurious wakeups?"); |
306 |
|
}}); |
307 |
|
|
308 |
|
long startTime = System.nanoTime(); |
318 |
|
assertNull(x); // ok |
319 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
320 |
|
fail("timed out"); |
321 |
+ |
if (t.getState() == Thread.State.TERMINATED) |
322 |
+ |
break; |
323 |
|
Thread.yield(); |
324 |
|
} |
325 |
|
} |