Skip to content

Fork-join

Category: Parallelism · Status: stub · Lessons: chapter 07, Parallelism

One line: Split a task into subtasks, run them in parallel, wait for all of them and combine their results — recursively, until the pieces are small enough to do directly.

Also called: divide and conquer in parallel, ForkJoinPool.

How it connects

flowchart LR
  n_fork_join["Fork-join"]
  n_join["Join"]
  n_task_parallelism["Task parallelism"]
  n_work_stealing["Work stealing"]
  n_fork_join -->|is a| n_task_parallelism
  n_fork_join -->|uses| n_join
  n_fork_join -->|uses| n_work_stealing
  classDef center stroke-width:3px
  class n_fork_join center
  classDef outside stroke-dasharray: 4 3
  class n_join,n_task_parallelism,n_work_stealing outside

In each language

Rust Rayon's join ↗ runs two closures, potentially in parallel, and returns both results
Java ForkJoinPool ↗ runs ForkJoinTasks, whose fork and join split and rejoin the work
C# Parallel.Invoke ↗ runs actions in parallel and returns when all have completed

Where to read more