Concurrency Edge Cases
Hard drills on race conditions, the ABA problem, lost notifications, and fairness. Mixed JS / Python / Java code stems with subtle bugs to spot and fix.
Question Bank
Hard
JavaScript
Python
Java
race-conditions
concurrency
multithreading
interview-prep
1,094 views
17
Spot the race condition. With two threads each running inc(10000), why is the final counter value typically less than 20000, and what is the standard fix?
Examples
Example 1:
Input: two threads each running inc(10_000) against a shared global counter
Output (buggy version): typically lands around 13_284 (varies per run) instead of 20_000
Output (fixed version): consistently 20_000 with a threading.Lock around counter += 1
Explanation: counter += 1 compiles to load + add + store, and CPython can switch threads between those bytecodes despite the GIL, losing increments. A Lock serializes the read-modify-write.5 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium