NOTE
2.13 concurrent
Goroutine and channel, the sync package, synchronization, happens-before rules, concurrency patterns, and multi-core CPU references.
This is a historical learning note and may contain outdated or incomplete understanding.
1. What There Is
1.1. goroutine + channel
1.2. sync Package
2. Synchronization
2.1. Sequential Consistency Model
Within the same Goroutine thread, the sequentially consistent memory model is guaranteed.
2.2. happens-before
Different Goroutines do not satisfy the sequentially consistent memory model by themselves. Explicitly defined synchronization events are needed as synchronization references.
2.2.1. channel
- buffered channel:
ch <- v≤v <- ch- Explanation: sending data to a buffered channel happens before receiving the data from the buffered channel
- That is, the writer needs to produce data first and put it into the channel; then the reader can consume the data from the channel
- unbuffered channel:
v <- ch≤ch <- v- Explanation: receiving data from an unbuffered channel happens before sending data to the unbuffered channel
- That is, when the reader reads data from the channel, it blocks until the writer produces data into the channel
3. Concurrency Patterns
4. Multi-core CPU
Go Multi-core Parallelization PythonWise: CPU Affinity in Go tsingson/cpuaffinity: pin goroutine to cpu core as thread
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub