0Pricing
Go Academy · Lesson

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

  1. sync.Mutex and sync.RWMutex
  2. sync.WaitGroup
  3. sync.Once and sync.Map
  4. Race Detector and Safe Patterns
← Back to Go Academy