Hasty Briefsbeta

Bilingual

Data races and the limits of ThreadSanitizer in C and Go

3 days ago
  • Data races are nondeterministic concurrent bugs; race detectors like ThreadSanitizer (TSan) help find them.
  • Most race detectors use LLVM's TSan, which evolved through three versions, with v3 being the current one.
  • TSan uses vector clocks (similar to FastTrack) to track thread ordering and detect races.
  • TSan has budget limitations: maximum 255 threads, 14-bit synchronization release counter, and 4 access history cells per 8-byte memory granule.
  • These budgets can cause TSan to miss real data races when thresholds are exceeded (e.g., many threads, many releases, or many distinct accesses to the same memory).
  • Go's sync.Pool can hide races due to a 128-slot hash table that creates false ordering between unrelated goroutines.
  • Despite limitations, TSan remains a valuable tool for detecting data races in C and Go programs.