liveBook · Manning

Fork-join model

As explained in Learn Concurrent Programming with Go

Fork/join is a concurrency pattern that performs parallel subtasks and then combines their results in a final join step.

The fork/join model runs independent subtasks in parallel, collects their partial results, and merges them before the program continues. In Go, the fork creates goroutines, while the join consumes a shared results channel after all work completes. section 10.2.2

A practical example scans a directory for Go files and finds the file containing the deepest nested code block. Each file is processed independently; the final step selects the greatest nesting depth. section 10.2.2

Deepest nested source file

Running the scanner can produce: “longestwords.go has the deepest nested code block of 6.”

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains the pattern through goroutines, channels, WaitGroup coordination, channel closure, and maximum-result selection.
Examples
Uses recursive directory scanning and curly-brace counting to identify the Go file with the deepest nested code block.
What you can do after
Build it from scratch: parallelize independent file scans, coordinate completion, close the results channel, and select the aggregate result.
How it connects
Connects goroutines, channels, WaitGroup synchronization, loop-level parallelism, data decomposition, worker pools, and pipelines.

Also explained in

Compare how 2 books explain fork-join model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.