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
Use the shared-workspace analogy to visualize concurrent threads modifying common resources. section 2.2.4
Inspect how threads share process memory while retaining private stacks. section 2.2.4
