← Lessons

quiz vs the machine

Silver1120

Concurrency

The Thread Sanitizer Revisited

A vector clock based detector that flags races with low false positives.

5 min read · intro · beat Silver to climb

What the sanitizer tracks

A thread sanitizer instruments every memory access at compile time. For each location it keeps a shadow state describing recent accesses and the vector clock of the thread that made them.

Vector clocks order events

A vector clock gives each thread a counter and lets the tool decide whether one access happens before another:

  • locks, joins, and atomic operations advance clocks
  • if two accesses have incomparable clocks they are concurrent
  • a concurrent pair where one writes is a data race

Why it has few false alarms

Because it reasons from real synchronization, the sanitizer reports only genuinely unordered accesses. It still observes a single run, so it can miss races on untaken paths but rarely cries wolf.

Key idea

The thread sanitizer uses vector clocks and shadow memory to decide whether two accesses are ordered, reporting a race only for a truly concurrent conflicting pair.

Check yourself

Answer to earn rating on the learn ladder.

1. What do vector clocks let the sanitizer decide?

2. Why does the sanitizer have few false positives?