liveBook · Manning

Parallelism

As explained in Learn Go with Pocket-Sized Projects

Parallel programming is a programming technique in which multiple computations execute concurrently to perform work at the same time.

Parallelism executes multiple computations at the same time. In Go, goroutines launch independent pieces of code, while the runtime and operating system schedule work across available execution resources. section 7.2.1 section 7.2

Cooking two pots

Cooking curry sauce and rice sequentially takes about 20 minutes. Cooking both for 10 minutes at once can reduce the total time to about 10 minutes, provided enough burners are available. Independent program tasks can benefit similarly. section 7.2.1

Use parallelism with these practical boundaries:

  • Launch goroutines when tasks can proceed independently without waiting for one another. section 7.2.1
  • Distinguish concurrency from parallelism: multiple goroutines may run independently without executing simultaneously on parallel cores. section 7.2.1
  • Expect overhead: creating goroutines and communicating with them can outweigh gains for very quick tasks, while CPU usage increases. section 9.3.2
  • Coordinate communicating goroutines with channels, which carry notifications such as newly available work. section 9.3.2

Parallel maze exploration

At a maze intersection, continue along one direction and start goroutines for the alternatives. Each explorer can continue until it finds the treasure or reaches a dead end; channels communicate new paths. section 9.3.2

Figure 9.4 exploration by different goroutines
A crossword puzzle with letters and numbers

Description automatically generated

Compare how different goroutines explore separate maze paths from a branching point. section 9.3.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains goroutines, scheduling, communication, and tradeoffs, but defers detailed differences between goroutines and system threads.
Examples
Illustrates parallelism with cooking two pots and exploring alternative maze paths.
What you can do after
Apply it via Go goroutines and channels while judging independence, communication overhead, and uncertain performance gains.
How it connects
Connects parallelism with goroutines, concurrency, channels, CPU schedulers, and multicore processors.

Also explained in

Compare how 37 books explain parallelism →

Related concepts

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