What is a Data Race versus a Race Condition? Can you have one without the other?
Last updated
Data race: two threads access the same memory concurrently, at least one writes, with no synchronization. It is undefined behavior under the C++ memory model (detectable by ThreadSanitizer).
Race condition: a broader logic bug where the result depends on timing or interleaving (e.g. check-then-act).
Either can exist alone: properly locked accesses can still form a wrong sequence (TOCTOU). A seemingly benign unsynchronized access is still UB even without visible bugs, so never rely on it.