liveBook · Manning

Thread communication

As explained in Learn Concurrent Programming with Go

Thread communication is the exchange of information or coordination signals between concurrently executing threads.

Thread communication is the exchange of information or coordination signals between concurrent executions. Threads solving one problem need communication and synchronization so they do not overwrite one another’s work. section 3.0 section 2.2.4

Choose between two broad communication approaches:

  • Memory sharing lets threads coordinate through the process’s shared memory, such as a global variable; synchronization controls prevent conflicting access. section 3.0 section 2.2.4
  • Message passing lets concurrent executions send information to one another instead of coordinating directly through shared state. Go provides channels for this approach. section 3.0 section 7.0

Shared memory makes changes made by one thread visible to other threads in the same process, enabling efficient collaboration. Each thread still keeps private stack space and its own program counter, so local variables are not automatically shared. section 2.2.4

Painters sharing a workspace

Several painters working on one canvas resemble threads sharing process memory. Without communication and synchronization, one painter can paint over another’s work; with cooperation, they can complete the project together. section 2.2.4

Figure 2.5 Painting concurrently and sharing space is analogous to using threads.

Use the shared-workspace analogy to visualize concurrent threads modifying common resources. section 2.2.4

Figure 2.6 Threads sharing the same process memory space

Inspect how threads share process memory while retaining private stacks. section 2.2.4

How Learn Concurrent Programming with Go covers it

How deep it goes
Defines two communication models and shared-memory behavior, while deferring detailed synchronization errors and channel construction.
Examples
Uses painters sharing a canvas, global-variable changes, private stacks, and Go channels as concrete illustrations.
What it assumes
Assumes concurrent execution and process memory, while defining shared memory, private stacks, message passing, and synchronization.
What you can do after
Evaluate whether shared memory or message passing fits a concurrent problem and recognize why synchronization is necessary.
How it connects
Connects memory sharing, message passing, synchronization, race conditions, channels, and communicating sequential processes.

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.