Here is a code fragment of java.util.concurrent.CountedCompleter
class (JDK 1.8.0_25).
/**
* If the pending count is nonzero, decrements the count;
* otherwise invokes {@link #onCompletion(CountedCompleter)}
* and then similarly tries to complete this task's completer,
* if one exists, else marks this task as complete.
*/
public final void tryComplete() {
CountedCompleter<?> a = this, s = a;
for (int c;;) {
if ((c = a.pending) == 0) {
a.onCompletion(s);
if ((a = (s = a).completer) == null) {
s.quietlyComplete();
return;
}
}
else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
return;
}
}
It makes me really confused. The documentation says: "and then similarly tries to complete this task's completer", but I do not see any invocations of 'complete' on this task's completer; or any other calls to it.
Have anybody worked with this class? Is it an issue with documentation or implementation? I might also cook it in a wrong way. Any ideas how to properly deal with this class is appreciated.