Software Engineer
mediumrace-conditions-and-fixes
What is a race condition and how do you fix it?
Answer
A **race condition** happens when program correctness depends on timing between concurrent operations.
**Fixes:**
- Use locks/mutexes around shared state.
- Use atomic operations or compare-and-swap.
- Use message passing (queues/actors) instead of shared memory.
- Prefer immutability.
**Interview tip:** provide a simple example (counter increments) and show a safe solution.
Related Topics
ConcurrencyMultithreading