Race Detector and Safe Patterns
Using -race flag and avoiding data races
What is a data race?
A data race occurs when two goroutines access the same memory location concurrently and at least one access is a write, without synchronisation. Data races cause undefined behaviour.
Enabling the race detector
Run or test with -race to enable Go's built-in race detector:
go run -race main.go
go test -race ./...All lessons in this course
- sync.Mutex and sync.RWMutex
- sync.WaitGroup
- sync.Once and sync.Map
- Race Detector and Safe Patterns