The Go Memory Model and Happens-Before
Synchronization guarantees and memory ordering
What is the memory model?
Go's memory model defines when writes to a variable by one goroutine are guaranteed to be visible to reads by another. Without these guarantees, concurrent programs can observe stale or inconsistent values.
Happens-before
A happens-before relationship guarantees that all writes before event A are visible at event B. If no happens-before exists, reads may observe any write — including the zero value.
All lessons in this course
- Stack vs Heap and Escape Analysis
- The Go Memory Model and Happens-Before
- Garbage Collector Internals
- Reducing Allocations: sync.Pool and Arenas