What is Priority inheritance?

Temporarily raising a low-priority task holding a resource to the priority of the high-priority task waiting for it, preventing priority inversion.

Field: Embedded Systems & Firmware

Japanese name: 優先度継承

How it works

While low-priority task L holds a mutex and high-priority task H waits for it, the operating system temporarily raises the priority of L to that of H. Medium-priority task M can then no longer preempt L, so L finishes sooner and releases the mutex. On release L drops back to its own priority and H runs.

What it does and does not prevent

It prevents H from waiting indefinitely because of unrelated medium-priority tasks, that is, unbounded priority inversion. H still waits for the time L needs to finish with the resource. With nested mutexes the waiting can chain and grow, and deadlock is not prevented. To limit these too, the priority ceiling protocol gives each mutex a ceiling equal to the highest priority of any task that uses it and raises the holder to that ceiling as soon as it locks the mutex.

In real operating systems

Priority inheritance belongs to mutexes, which have an owner. In FreeRTOS, mutexes have priority inheritance and binary semaphores do not. With POSIX threads it is selected with the mutex attribute PTHREAD_PRIO_INHERIT. On Mars Pathfinder, enabling priority inheritance on a VxWorks mutex cured the repeated resets.

Try it: questions about Priority inheritance

Which describes priority inheritance, used to prevent priority inversion?

  1. ALower the high-priority task to the low task's priority
  2. BGive all tasks the same priority
  3. CTemporarily raise the low-priority task holding a resource to the priority of the high-priority task waiting for it
Show answer and explanation

Answer: C. Temporarily raise the low-priority task holding a resource to the priority of the high-priority task waiting for it

With priority inheritance, when a high-priority task starts waiting for a mutex held by a low-priority task, the low task temporarily gets the high task's priority. It then proceeds without being preempted by medium tasks and returns to its original priority on releasing the resource. The high task's wait is then roughly bounded by the time the low task uses the resource, although nested mutexes can chain the waits and make them longer. Many RTOS mutexes provide this feature.

FAQ

Does priority inheritance work if a semaphore is used for mutual exclusion?

Generally not. A semaphore has no owner, so the operating system cannot tell whose priority to raise. Use a mutex to protect a shared resource.

Does priority inheritance remove all concern about waiting time?

No. The waiting task still waits until the holder is done. Keep the section that holds the resource short, and do not do slow work or block on something else inside it.

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary