mirror of
https://github.com/openjdk/jdk.git
synced 2026-06-10 12:37:09 +00:00
Backport 4a84d0414ef0e2680a6b5a6ca0af19f30251a520
This commit is contained in:
parent
cce810ed30
commit
e263caae09
@ -418,19 +418,15 @@ public abstract class ForkJoinTask<V> implements Future<V>, Serializable {
|
||||
for (;;) {
|
||||
if ((s = status) < 0)
|
||||
break;
|
||||
else if (interrupts < 0) {
|
||||
s = ABNORMAL; // interrupted and not done
|
||||
break;
|
||||
}
|
||||
else if (Thread.interrupted()) {
|
||||
if (!ForkJoinPool.poolIsStopping(pool))
|
||||
interrupts = interruptible ? -1 : 1;
|
||||
else {
|
||||
interrupts = 1; // re-assert if cleared
|
||||
if (ForkJoinPool.poolIsStopping(pool)) {
|
||||
try {
|
||||
cancel(true);
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
} catch (Throwable ignore) { }
|
||||
}
|
||||
if ((interrupts = interruptible ? -1 : 1) < 0) {
|
||||
s = ABNORMAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (deadline != 0L) {
|
||||
|
||||
@ -663,6 +663,23 @@ public class ForkJoinPoolTest extends JSR166TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testCallerInterruptedDuringSubmit() throws InterruptedException, ExecutionException {
|
||||
final Thread submitter = Thread.currentThread();
|
||||
final ExecutorService p = new ForkJoinPool(1);
|
||||
try (PoolCleaner cleaner = cleaner(p)) {
|
||||
for (int i = 0; i < 512; ++i) { // Enough repetitions such that any race condition is bound to materialize
|
||||
try {
|
||||
p.submit(submitter::interrupt).get();
|
||||
// If we don't get an InterruptedException, then the current thread should be interrupted
|
||||
assertTrue(Thread.interrupted());
|
||||
} catch (InterruptedException e) {
|
||||
// If we do get an InterruptedException, then the current thread should not be interrupted
|
||||
assertTrue(!Thread.interrupted());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get of submit(callable) throws ExecutionException if callable
|
||||
* throws exception
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user