RTOS & Real-Time Concepts · Interview question

What four conditions are required for a deadlock?

A strong answer

The four Coffman conditions, all of which must hold simultaneously for a deadlock to be possible: mutual exclusion (resources are held exclusively, only one owner at a time, inherent to mutexes); hold-and-wait (a task holds at least one resource while waiting to acquire another); no preemption (a resource can't be forcibly taken from its holder, it's only released voluntarily); and circular wait (there exists a cycle of tasks where each is waiting for a resource the next task in the cycle holds). The reason this framing is useful is that breaking any single one of the four makes deadlock impossible, so every prevention technique maps to eliminating one condition: consistent lock ordering eliminates circular wait; acquiring all locks at once or releasing before acquiring eliminates hold-and-wait; timeouts with release-and-retry effectively break the no-preemption/indefinite-wait condition by making the wait give up; and using lock-free structures or not sharing the resource eliminates mutual exclusion. In practice circular wait is the easiest to attack (via lock ordering), which is why that's the go-to fix.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Deadlocks & How to Avoid Them

Two tasks each holding a lock the other needs, frozen forever: the four conditions for deadlock, and the fixes (consistent lock ordering, avoiding hold-and-wait, and timeouts).

More Deadlocks & How to Avoid Them questions

Browse all 472 interview questions
What four conditions are required for a deadlock? | EmbeddedPrep.io