"go test -race" Under the Hood
summary
The go race detector claims to find real data races by having the compiler insert calls around memory and sync operations and by delegating detection to ThreadSanitizer (tsan) which implements a happens-before check using vector clocks. Instrumentation adds race_read/race_write calls and the runtime keeps compact shadow state — only 4 shadow cells per 8-byte application word and scalar clocks — so reports have no false positives but can miss races on unobserved executions and impose significant runtime and memory overhead, so it’s mainly for tests and staging.
AI-written summary · about
chapters (13)
- 0:00Intro
- 1:26data races
- 5:18race detectors
- 6:27go race detector
- 7:58concurrency in go
- 14:41vector clocks
- 20:00go run -race
- 25:24threadsanitizer
- 27:01shadow state
- 29:33race detection
- 32:55evaluation
- 36:31Optimization 1
- 38:17alternatives
related talks
22mData race detection
26mGo Plays Nice With Your Computer - Race Detection and Freedom!
07mRace Conditions in Details
19mRuntime Detection of Data Races in OCaml with ThreadSanitizer
32mTesting in Go: from basic to advanced
24mRacerD - Compositional Static Race Detection
15mSound and partially-complete static analysis of data-races in GPU programs
32mMaTSa: Race Detection in Java
