Avoiding Data Races
Keep parallel writes safe.
What Is a Data Race
A data race happens when two threads touch the same memory at once and at least one writes. The result becomes unpredictable. ⚠️
The Classic Trap
Many workers adding into one shared total will clash. Updates get lost because writes overlap and stomp each other.
total += out[i] # shared, unsafe in parallel