[concurrency-interest] ForkJoinTask.externalAwaitDone() co-operates only with commonPool?

Ruslan Cheremin cheremin at gmail.com
Sun Feb 5 10:34:00 EST 2017


Tracing the execution of FJTask.join() I've found the code
externalAwaitDone() (listed below), from which it is obvious external
(non-FJP) thread will try to help to execute tasks _only from commonPool_,
and just blocks otherwise.

I was sure FJP.commonPool is not any kind special, just the same as any
other FJPool. From the code below it looks like it is special: any external
thread doing .join() will try to help only commonPool's tasks, but not any
other FJPools.

Why it is implemented this way? Can't .join() always try to help the actual
FJPool current FJTask is enqueued into?

It is also interesting: is there any other places in FJTask/Pool machinery
there commonPool is treated specially?

--------- ForkJoinTask----

private int externalAwaitDone() {
        int s = ((this instanceof CountedCompleter) ? // try helping
                 ForkJoinPool.common.externalHelpComplete(
                     (CountedCompleter<?>)this, 0) :
                 ForkJoinPool.common.tryExternalUnpush(this) ? doExec() :
0);
        if (s >= 0 && (s = status) >= 0) {
            boolean interrupted = false;
            do {
                if (U.compareAndSwapInt(this, STATUS, s, s | SIGNAL)) {
                    synchronized (this) {
                        if (status >= 0) {
                            try {
                                wait(0L);
                            } catch (InterruptedException ie) {
                                interrupted = true;
                            }
                        }
                        else
                            notifyAll();
                    }
                }
            } while ((s = status) >= 0);
            if (interrupted)
                Thread.currentThread().interrupt();
        }
        return s;
    }

----
Ruslan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170205/3ad6b718/attachment.html>


More information about the Concurrency-interest mailing list