A race condition occurs when a system’s outcome depends on the uncontrolled timing or ordering of concurrent events. The same operations can therefore produce different results even when the code is data-race-free. section 2.4 section 2.0
Distinguish the broader timing problem from the specific memory-access problem:
- A data race occurs when concurrent threads access the same memory location, with at least one access writing; a race condition concerns any uncontrollable event ordering. section 2.4
- All data races are race conditions, but eliminating data races does not guarantee deterministic behavior; thread order and database-call duration can still affect outcomes. section 2.4
- A mutex can serialize access to shared data and remove the data race, but it cannot by itself determine which thread runs first. section 2.4
- Impact depends on the result: a temporarily inaccurate like count may be harmless, while an outdated bank balance can be serious. section 2.4
// Thread 1 code coffee.price = 10 // Thread 2 code print(coffee.price)
Shows a minimal shared-resource example in which one thread writes a price while another reads it, making the possible outcomes depend on scheduling. section 2.4
// Thread 1 code mutex.Lock() coffee.price = 10 mutex.Unlock() // Thread 2 code mutex.Lock() print(coffee.price) mutex.Unlock()
Contrasts mutex-protected access with deterministic sequencing: mutual exclusion prevents simultaneous access, but either thread may still execute first. section 2.4
























