race detector
A checking mode, turned on with -race, that makes a Go program report when two goroutines touch the same memory unsafely.
In more detail
It watches memory accesses while tests or programs run and prints both conflicting stack traces when it finds a data race. It only finds races that actually happen during that run, so exercise concurrent paths in tests. It slows the program down, so use it in testing rather than production.
Example
go test -race ./...Related terms
- data race — A bug where two goroutines access the same memory at the same time and at least one of them writes, without any synchronization.
- goroutine — A function running concurrently with the rest of a Go program, started by putting the go keyword before a call.
- go test — The go subcommand that builds a test binary from the _test.go files in a package, runs every test function and reports what failed.
- mutex — A lock that lets only one piece of code at a time run a critical section or do a particular piece of work.
Taught in
- Goroutines and Concurrent Execution — Concurrent Systems Programming with Go