[concurrency-interest] ForkJoinTask does not re-check task status entailing overhead

Rémi Barat rba at activeviam.com
Tue Nov 6 09:50:21 EST 2018


Hi, Doug,

Thank you very much for your quick answer. We originally made exec() return
false since the javadoc says "Returns: true if this task is known to have
completed *normally*". Maybe it should be updated so that it matches your
answer, that "... assuming that exec() returns true if done (either
normally or exceptionally)".

Do you see any potential issue we might have after changing this return
value from false to true?
It looks like it will simply set the DONE flag in the status through
setDone in doExec, which should be idempotent with the already recorded
abnormal completion of the super.cancel call.
However I'm not 100% sure of this, and we're using ForkJoinTasks and
CountedCompleters quite extensively in our software. Hopefully our test
suite will cover this!

Rémi

On Tue, Nov 6, 2018 at 1:12 PM Doug Lea via Concurrency-interest <
concurrency-interest at cs.oswego.edu> wrote:

> On 11/6/18 4:11 AM, Rémi Barat via Concurrency-interest wrote:
> > Hi,
> >
> > In one of our test we create around 260,000 ForkJoinTasks from one
> > parent task. The parent task sets a flag which causes every child task
> > to cancel itself (using super.cancel).
> >
> > Please find attached a class to reproduce the test. In Java 8, this test
> > is instantaneous, whereas it takes around 25s on my machine with Java 11.
> > ...
>
> > The question is: is the check on the task status necessary, or did we do
> > something wrong?
>
> The check is not necessary assuming that exec() returns true if done
> (either normally or exceptionally), which it is required to do. You
> should change the line:
>
>         @Override
>         protected boolean exec() {
>             if (!interrupted.get()) {
>                 executeTask();
>                 return true;
>             } else {
>                 super.cancel(false);
>                 return true; // was false
>             }
>         }
>
> (In jdk8, it happened to work OK even without doing this.)
> You could also add a line in your checkInterrupt method:
>
>         protected void checkInterruption() {
>             if (interrupted.get()) {
>                 cancel(false);    // added
>                 throw new CancellationException();
>             }
>         }
>
>
> -Doug
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20181106/f9751a7f/attachment.html>


More information about the Concurrency-interest mailing list