Minimal fork-join helpers for CPU-bound tree recursion.
The small set of primitives needed by the tree algorithms:
Minimal fork-join helpers for CPU-bound tree recursion. The small set of primitives needed by the tree algorithms: - enter the common pool once at the root - fork one recursive branch - compute the other branch inline - join and combine
Shared ForkJoinPool used by collection parallel operations.
Shared ForkJoinPool used by collection parallel operations.
(fork-join [left-sym left-expr right-sym right-expr] combine-expr)Fork left-expr as a RecursiveTask, compute right-expr inline, then join.
This left-fork/right-inline shape matches the intended recursive divide-and-conquer usage: keep one branch local, make the other branch stealable by ForkJoinPool worker threads, then combine the results.
ForkJoin worker threads do not propagate Clojure dynamic bindings.
Forked bodies must therefore rely only on explicit arguments
captured at the parallel entry point, not on dynamic vars such as
order/*compare* or tree/*t-join*.
Fork left-expr as a RecursiveTask, compute right-expr inline, then join. This left-fork/right-inline shape matches the intended recursive divide-and-conquer usage: keep one branch local, make the other branch stealable by ForkJoinPool worker threads, then combine the results. ForkJoin worker threads do not propagate Clojure dynamic bindings. Forked bodies must therefore rely only on explicit arguments captured at the parallel entry point, not on dynamic vars such as `order/*compare*` or `tree/*t-join*`.
(invoke-root f)Run thunk in the common pool and return its result.
This is the outer entry point into fork-join execution. Recursive work
below that point should use fork-join
Run thunk in the common pool and return its result. This is the outer entry point into fork-join execution. Recursive work below that point should use `fork-join`
(recursive-task f)Create a RecursiveTask from a nullary thunk.
This avoids the extra Callable -> ForkJoinTask adaptation layer used by ForkJoinTask/adapt while keeping task construction generic.
Create a RecursiveTask from a nullary thunk. This avoids the extra Callable -> ForkJoinTask adaptation layer used by ForkJoinTask/adapt while keeping task construction generic.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |