Go Memory Model
- Happens-before is the rule for visibility.
- Without synchronization, writes are not guaranteed to be seen in order.
Safe publication
- Build state first.
- Publish once.
- Do not mutate after publication.
Common patterns
sync.Mutexfor mutable shared state.channelclose / receive for lifecycle boundaries.atomic.Pointer[T]for immutable snapshots.
Anti-pattern
- Reading shared variables with no edge.
- Publishing mutable structs and updating later.
Practice focus
- Implement a publish cell with atomic pointer swaps.
- Distinguish empty, load, and swap semantics.
1 / 1