A data race occurs when multiple threads access the same memory location concurrently, at least one access writes, and no adequate synchronization protects the access. The result can include corrupted data, instability, and subtle bugs. section 2.4
A data race is a specific memory error; a race condition is broader: the outcome depends on uncontrolled timing. Eliminating data races does not guarantee deterministic results, because thread order or database-call duration can still change the outcome. section 2.0 section 2.4
// Thread 1 code coffee.price = 10 // Thread 2 code print(coffee.price)
An unsynchronized write and read of the same price can produce an unpredictable result. section 2.4
// Thread 1 code mutex.Lock() coffee.price = 10 mutex.Unlock() // Thread 2 code mutex.Lock() print(coffee.price) mutex.Unlock()
A mutex serializes access to the price and removes the data race, although execution order can still leave the printed value nondeterministic. section 2.4
Safe access does not ensure a fixed result
If one thread writes coffee.price as 10 while another prints it, unsynchronized access creates a data race. Locking both operations with a mutex removes that memory error, but the printer may still run first and show the initial price. A brief incorrect like count may be harmless; an outdated bank balance is more serious. section 2.4




