When Go's Race Detector Passes but an Update Is Lost

A balance starts at 100. One worker adds 10, another subtracts 20. When both updates have finished, the balance should be 90. But a Go program can print 80, even when go test -race reports no data race. The detector checked memory accesses; it didn’t check whether the whole balance update was correct. The experiment below forces the problematic ordering instead of hoping that a fast machine triggers it. It uses Go 1.27.x on Linux/amd64; the relevant atomic semantics come from Go’s memory model rather than that particular machine. ...

October 30, 2026 · 5 min · 995 words · Jack Li