liveBook · Manning

Concurrency

As explained in Learn Go with Pocket-Sized Projects

Concurrency is the structuring and execution of multiple computational activities that can make progress during overlapping periods.

Concurrency structures multiple computational activities so they can make progress during overlapping periods. Go treats it as a core design concern for modern multicore, networked software and provides lightweight goroutines for independent execution. section 1.1 section 7.2.1

Concurrency is not the same as parallelism: goroutines can execute independently without guaranteeing simultaneous execution on separate processor cores. Concurrency concerns structuring code; parallelism describes execution. section 7.2.1

a = taskA()
b = taskB() #1

A compact task-ordering example contrasts ordinary sequential calls with work that can be launched independently. section 7.2.1

Choose a concurrency strategy by identifying the workload and its limiting resource:

  • CPU-bound work, such as video encoding, is constrained by machine architecture and available processor capacity. section 7.5.2
  • I/O-bound work, such as counting lines across files or making REST requests, is constrained by operating-system, server, or remote-service limits. section 7.5.2
  • Excessive concurrency can overload the system; benchmark choices such as buffered-channel size on representative hardware. section 7.5.2

Cooking two tasks concurrently

Cooking sauce and rice sequentially takes about twenty minutes, while preparing both at the same time can take about ten minutes when separate burners are available. Goroutines apply the same overlap to independently launchable tasks. section 7.2.1

A practical concurrency exercise is a cache that stores, reads, and deletes key-value pairs safely under concurrent access. Testing exposes an inadequate first design before stronger synchronization and expiration policies are added. section 7.0

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Distinguishes concurrency from parallelism, introduces goroutines, and selects strategies by workload limits and benchmarking.
Examples
Uses cooking tasks, file line counting, video encoding, REST requests, and a concurrency-safe key-value cache.
What you can do after
Evaluate workloads, structure independent tasks with goroutines, and design safer concurrent components.
How it connects
Connects goroutines with parallelism, race conditions, mutexes, channels, caching, and workload classification.

Also explained in

Compare how 23 books explain concurrency →

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.