Skip to content

Commit 334a8f9

Browse files
committed
For starvation check openjdk#5
1 parent 8907aca commit 334a8f9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,7 @@ final void push(ForkJoinTask<?> task, ForkJoinPool pool,
12911291
unlockPhase();
12921292
if (room < 0)
12931293
throw new RejectedExecutionException("Queue capacity exceeded");
1294-
else if ((room == 0 || s == base || a[m & (s - 1)] == null) &&
1295-
pool != null)
1294+
else if ((room == 0 || a[m & (s - 1)] == null) && pool != null)
12961295
pool.signalWork(); // may have appeared empty
12971296
}
12981297
}
@@ -1991,7 +1990,7 @@ final void runWorker(WorkQueue w) {
19911990
if ((q = qs[j = i & (n - 1)]) != null &&
19921991
(a = q.array) != null && (cap = a.length) > 0) {
19931992
for (int m = cap - 1, pb = -1;;) { // track progress
1994-
ForkJoinTask<?> t; int b; long k;
1993+
ForkJoinTask<?> t; int b, nb; long k;
19951994
t = (ForkJoinTask<?>)U.getReferenceAcquire(
19961995
a, k = slotOffset(m & (b = q.base)));
19971996
if (q.base != b) // inconsistent
@@ -2010,13 +2009,15 @@ else if (t == null) {
20102009
}
20112010
}
20122011
else if (U.compareAndSetReference(a, k, t, null)) {
2013-
ForkJoinTask<?> next = a[(q.base = b + 1) & m];
2012+
ForkJoinTask<?> next = a[(nb = q.base = b + 1) & m];
20142013
w.nsteals = ++nsteals;
20152014
w.source = j; // volatile
20162015
rescan = true;
2017-
if (next != null &&
2018-
(!propagated || t.getClass().getSuperclass() ==
2019-
interruptibleTaskClass)) {
2016+
if ((t.getClass().getSuperclass() ==
2017+
interruptibleTaskClass) ?
2018+
(next != null ||
2019+
(j & 1) == 0 && q.top - nb > 0) :
2020+
(!propagated && next != null)) {
20202021
propagated = true;
20212022
signalWork();
20222023
}

0 commit comments

Comments
 (0)