Ch. 21 · Operating Systems

Priority Inversion and Lock Ownership

Priority Inversion and Lock Ownership. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readadvancedupdated Oct 3, 2026

A high-priority task can wait on a lock held by a lower-priority task. Scheduling interference can extend the wait beyond intuition.

Before you start

You should understand processes, threads, memory and basic file operations. Track ownership and state changes over time. For concurrent scenarios, write down at least two possible execution orders; the same instructions can behave differently when scheduling or resource availability changes.

The practical goal is to reason through this situation: A medium-priority task delays the lower-priority lock owner while urgent work remains blocked. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Identify the blocked urgent task

A high-priority worker waits for a lock held by lower-priority work.

Step 2: Trace competing scheduling

Medium-priority work can delay the owner from releasing the lock.

Step 3: Reduce the blocking path

Bound critical sections and use suitable inheritance support where required.

Worked scenario

A medium-priority task delays the lower-priority lock owner while urgent work remains blocked.

Low-priority L holds a lock needed by high-priority H. Medium-priority M keeps running ahead of L, extending H’s wait. Raising H’s priority again cannot release the lock. A suitable priority-inheritance mechanism can temporarily help L complete its critical section, subject to the system’s supported scheduling behavior.

Common mistake

Raising the waiting task’s priority alone does not free the lock.

Verify the behavior

Trace the three-task schedule and bound the maximum lock-holding work.

Interview exercise

Reduce inversion risk.

Answer and reasoning

Keep critical sections bounded and use suitable scheduling or priority-inheritance support where the system requires it.

Continue learning

Compare the scenario with the Operating Systems interview questions and test your understanding with the Operating Systems MCQs. For terminology and implementation details, consult the reference material.

More in Operating Systems

read ✓Operating Systems · hard

Operating Systems: CPU Cache Locality

Improve performance with spatial and temporal locality, avoid pointer chasing, and understand false sharing between threads.

~2 min readread →
read ✓Operating Systems · hard

Copy-on-Write Memory and fork

How copy-on-write lets fork share pages until a write, why RSS can be misleading, and the implications for memory and latency.

~2 min readread →
read ✓Operating Systems · hard

Operating Systems: epoll and select

How select, poll and epoll report I/O readiness, and the difference between level- and edge-triggered notifications.

~2 min readread →
esc