Software Engineer
mediumdeadlocks-and-prevention
What is a deadlock and how do you prevent it?
Answer
A **deadlock** occurs when multiple actors wait forever for each other’s resources.
**Prevention strategies:**
- Acquire locks in a consistent global order.
- Use timeouts and retries.
- Reduce lock scope/duration.
- Prefer lock-free or immutable designs when possible.
In databases, proper indexing and shorter transactions can also reduce deadlock risk.
Related Topics
ConcurrencyDatabasesOperating Systems