RTOS & Real-Time Concepts · Interview question

Does priority inheritance prevent deadlock?

A strong answer

No, and assuming it does is a dangerous misconception. Priority inheritance solves priority inversion: it temporarily boosts a mutex holder's priority so medium-priority tasks can't preempt it, bounding how long a high-priority task waits. But that mechanism does nothing about a circular wait. In a deadlock, two tasks each hold a lock the other needs; boosting either holder's priority doesn't help, because the holder isn't being preempted, it's itself blocked waiting for the other lock that will never be released. There's no forward progress to enable; the cycle is the problem, not CPU starvation of a holder. So a system using priority-inheriting mutexes (like FreeRTOS's) is still fully exposed to deadlock if it acquires multiple locks in inconsistent orders. The two problems are orthogonal: inheritance for inversion (a timing/bounding issue), and lock ordering / avoiding hold-and-wait for deadlock (a liveness/cycle issue). You need both disciplines, use inheriting mutexes to bound inversion and enforce lock ordering to prevent deadlock. Conflating them leads people to think "I used a proper mutex, so I'm safe," which is false for the multi-lock case.

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
Does priority inheritance prevent deadlock? | EmbeddedPrep.io