Last Updated: May 22, 2026
When two goroutines write to the same variable without coordination, the result is a data race: a bug whose output changes between runs and whose root cause is invisible in the source code. sync.Mutex is the standard tool for making a critical section run one goroutine at a time, and sync.RWMutex is its read-heavy cousin. This lesson covers both, the discipline around using them, and the bugs that result when that discipline is absent.