What is deadlock and how can operating systems prevent it?
Reported in Freshworks interview loops. OS synchronization question covering four necessary conditions and mitigation.
Interview scenario
Often asked in Freshworks technical or coding rounds. Prepare a clear spoken answer plus key trade-offs.
Model answer
Try answering aloud first
Cover trade-offs, structure, and a concrete example before revealing the baseline response.
How to frame this at Freshworks: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.
Deadlock occurs when threads/processes circularly wait on resources held by each other—none can proceed. Four necessary conditions (Coffman): mutual exclusion, hold and wait, no preemption, circular wait.
Prevention strategies: impose lock ordering (always acquire A before B), lock timeouts with retry, try-lock patterns, or eliminate hold-and-wait by acquiring all locks upfront.
Detection and recovery: OS or DB detects wait-for graph cycles and kills victim transaction. Banker's algorithm for safe states—more theoretical in interviews.
Engineering examples: DB deadlocks on row locks—retry with backoff; distributed systems use lease-based locks (Redis Redlock with caution); prefer immutable data and message passing to shared mutable locks.
Discussion
Comments (0)
Share how this question came up in your loop, or add tips for others preparing.
Log in to comment on this question.