liveBook · Manning

Concurrency primitive

As explained in Learn Concurrent Programming with Go

Classical concurrency primitives are low-level synchronization mechanisms traditionally used to coordinate concurrent execution.

Concurrency primitives are low-level synchronization mechanisms for coordinating concurrent executions that share memory. Common tools include mutexes, condition variables, and semaphores. section 1.5.2 section 9.1

Use classical primitives to:

  • Restrict simultaneous access to shared memory and reduce race conditions with mutexes or semaphores. section 9.1
  • Coordinate execution with condition variables, semaphores, waitgroups, and related synchronization tools. section 1.5.3
  • Choose shared-memory synchronization when it fits the problem better or performs better than CSP-style message passing. section 1.5.2

The model offers precise control but exposes scheduling and memory-access complexity. Interleaved execution can create hard-to-reproduce races, verbose critical sections, unclear data flow, and difficult maintenance. section 8.2.1 section 9.1

CSP-style programming provides an alternative: isolated goroutines communicate through channels. Classical primitives remain useful when message passing is not the appropriate model. section 1.5.2

Figure 8.11 Achieving the right balance between code simplicity and performance

Compare the simplicity of message-passing designs with the performance and control available from shared-memory primitives. section 8.2.1

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains mutexes, condition variables, and semaphores, then addresses scheduling, races, complexity, and implementation trade-offs.
Examples
Uses mutexes, condition variables, semaphores, waitgroups, channels, and shared-memory critical sections as concrete artifacts.
What it assumes
Assumes concurrent executions and shared memory, while establishing traditional synchronization before introducing CSP-style programming.
What you can do after
Builds synchronization tools from scratch and makes better-informed choices about when and how to use them.
How it connects
Connects shared memory, goroutines, mutexes, condition variables, semaphores, channels, CSP, and race conditions.

Also explained in

Compare how 2 books explain concurrency primitive →

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.