Skip to content

Race detector

Category: Testing and tools · Status: stub · Lessons: chapter 09, Testing and tools (planned)

One line: A tool that instruments memory accesses as the program runs and reports the data races that actually happened in that run — ThreadSanitizer, Go's -race.

Also called: ThreadSanitizer, TSan, go -race, Helgrind.

How it connects

In each language

Rust Unstable -Zsanitizer=thread on supported targets, usually with -Zbuild-std
Go go test -race: needs cgo, and typically costs 5-10x memory and 2-20x time
C ThreadSanitizer ↗: compile and link with -fsanitize=thread in Clang or GCC ↗; typical slowdown 5x-15x
C++ The same ThreadSanitizer ↗ -fsanitize=thread, which also reports lock-order inversions
Python CPython itself can be built with --with-thread-sanitizer (added in 3.13)
Elsewhere Valgrind's Helgrind ↗ finds data races, lock-ordering problems and misuses of the pthreads API

Where to read more