Explain Deadlock and How to Prevent It
viaGlassdoor
Question: What is a deadlock situation, and how can it be prevented?
Answer framing: A deadlock occurs when two or more processes/threads are each waiting for a resource held by another, forming a cycle of dependencies, so none can proceed. The four necessary conditions (Coffman conditions) are mutual exclusion, hold-and-wait, no preemption, and circular wait. Prevention strategies break at least one condition: impose a strict resource-acquisition ordering to prevent circular wait, use timeouts/try-lock with backoff to avoid indefinite hold-and-wait, or allow preemption of held resources. Detection-and-recovery (via a wait-for graph) is an alternative to strict prevention in systems where deadlocks are rare.
asked …