How Tech - Systems Programming

How Tech - Systems Programming

Debugging Race Conditions in C using Thread Sanitizers (TSAN)

Feb 23, 2026
∙ Paid

The Problem: Races Hide Until They Don’t

You’ve got a multithreaded counter in production. Works fine for weeks. Then at 2 AM, someone reports incorrect totals. You add logging - the race disappears. Remove logging - race returns. Classic Heisenbug.

Data races happen when two threads access the same memory without proper synchronization and at least one access is a write. The CPU’s store buffer, cache coherency delays, and compiler reordering mean your carefully-written C code doesn’t execute in the order you wrote it. That counter++ you thought was atomic? It’s load-modify-store, and another thread can slip between those operations.

User's avatar

Continue reading this post for free, courtesy of Systems.

Or purchase a paid subscription.
© 2026 Sumedh S · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture