๐ Priority Inversion in Semaphore (36 MCQs)
Priority Inversion During Semaphore-Based Resource Access
Priority inversion is a scheduling problem in which a high-priority process waits for a resource held by a lower-priority process. Semaphore-based synchronization can create this situation when a low-priority thread acquires a semaphore before a high-priority thread requests it. Medium-priority activity may then delay the lock holder, indirectly preventing the high-priority thread from proceeding.
Why Resource Ownership Can Conflict with Scheduling Priority
Priority scheduling normally favours high-priority tasks, but resource dependencies complicate that policy. A high-priority task cannot enter a protected section while a lower-priority task holds the required lock. If intermediate-priority tasks repeatedly preempt the lock holder, the high-priority task experiences an unexpectedly long delay despite its scheduling priority.
Priority Inheritance and Priority Ceiling Mechanisms
Priority inheritance temporarily raises the priority of a low-priority lock owner to that of the highest-priority process waiting for its resource. The owner can then execute and release the semaphore-protected resource more quickly. Priority ceiling protocols assign an appropriate elevated priority according to resource access rules, reducing certain priority inversion and deadlock risks.
Three Tasks Competing for One Protected Resource
Consider low-priority task L holding a semaphore, high-priority task H waiting for it, and medium-priority task M becoming runnable. Without priority inheritance, M may repeatedly preempt L, delaying H. With priority inheritance, L temporarily receives H's effective priority, allowing it to finish the protected operation and release the resource.
Real-Time Response Delays and Scheduling Reliability
Priority inversion can violate timing requirements in real-time systems and delay critical operating system services. Priority inheritance limits the time a high-priority task waits for a lower-priority lock holder under suitable assumptions. However, it introduces priority-management complexity, and ordinary semaphores do not universally provide inheritance automatically. The chosen synchronization primitive must support the required protocol.
Misconceptions About Priority Inversion
'Priority inversion means a scheduler permanently reverses every priority' is incorrect because it describes a resource-dependent delay. 'A high-priority task always immediately preempts a low-priority lock holder' is incorrect because locking can prevent progress. 'Every semaphore automatically implements priority inheritance' is incorrect because support depends on the primitive and operating system.
Exam Focus: Tracing Priority Inversion and Inheritance
Draw the execution order of high-, medium-, and low-priority tasks competing for a semaphore. Identify the lock owner and explain how medium-priority execution delays the high-priority task. Compare priority inheritance with priority ceiling and distinguish ordinary priority scheduling from resource-aware scheduling protocols.
Key Terms of Priority Inversion
- Priority inversion - High-priority task delayed by lower-priority ownership.
- Priority inheritance - Temporarily raises a lock owner's priority.
- Priority ceiling - Assigned resource-related priority limit.
- Lock owner - Task holding a protected resource.
- Real-time task - Task with timing requirements.
- Preemption - Suspension of running task execution.
๐ All Priority Inversion in Semaphore MCQs
Q1. Tasks H, M, and L have priorities H > M > L. L holds semaphore S, H blocks while requesting S, and M preempts L. What scheduling problem is occurring?
๐ Explanation: H cannot proceed because L owns the semaphore, while M delays L from releasing it. A lower-priority task therefore indirectly delays a higher-priority task, which is the defining priority-inversion pattern.
Q2. A medium-priority task M never requests semaphore S, yet its execution delays high-priority H, which is waiting for S held by low-priority L. Why does M matter?
๐ Explanation: M has no direct lock dependency with H. Its effect is indirect: by preempting L, it prevents the resource owner from completing the protected work and releasing S, so H remains blocked.
Q3. A trace shows L holding S when H blocks at time 2 ms. M then runs until 9 ms, after which L executes for 3 ms and releases S. Ignoring wake-up overhead, how long is H blocked?
๐ Explanation: H blocks at 2 ms and becomes eligible when S is released at 12 ms. Its blocking interval is therefore 12 โ 2 = 10 ms, including M execution and L finishing the protected operation.
Q4. A student claims that raising H from priority 9 to priority 12 solves inversion because H will then preempt L. What is wrong with this reasoning?
๐ Explanation: The flawed step assumes a blocked task can execute merely by receiving a larger priority. H still cannot enter the protected region while L owns S; improving the owner's ability to run addresses the dependency.
Q5. Under basic priority inheritance, H at priority 10 waits for semaphore S held by L at priority 2. What effective priority should L receive while H remains blocked, assuming no other higher-priority dependency?
๐ Explanation: Priority inheritance raises the owner to the highest priority of relevant blocked waiters. Since H waits at priority 10 and no higher waiter exists, L temporarily executes with effective priority 10 while retaining its original base priority.
Q6. In a system without inheritance, the duration of H's wait grows whenever unrelated medium-priority work becomes runnable. What does this indicate about the inversion?
๐ Explanation: The resource owner's critical-section work has not necessarily changed. Additional runnable medium-priority work delays the owner, so H's blocking depends on unrelated scheduling activity and may become difficult to bound.
Q7. A mutex uses priority inheritance, but L still needs 5 ms of CPU work to finish its critical section after H blocks. What does inheritance change?
๐ Explanation: Inheritance changes the owner's scheduling priority; it does not erase instructions or shorten their execution requirement. H can still wait for the owner to complete the remaining protected operation and release the mutex.
Q8. H is changed from blocking on S to continuously polling the semaphore while L owns it. Why can this worsen response time on a single CPU?
๐ Explanation: While H polls, it consumes CPU without making S available. That processor time may further delay L, the only task able to release the resource, increasing the time before H can proceed.
Q9. After H blocks, L needs 4 ms of CPU execution to release S. M executes for 7 ms before L resumes, and no other delays occur. What is H's blocking time?
๐ Explanation: H waits through both intervals: M uses 7 ms before L resumes, and L then needs 4 ms to release S. Thus the blocking time is 7 + 4 = 11 ms, ignoring dispatch and wake-up costs.
Q10. Read this priority timeline: time 0โ4 ms, L runs at effective priority 2; at 4 ms H blocks on S; time 4โ10 ms, L runs at effective priority 9; at 10 ms L releases S. For how long was L boosted?
๐ Explanation: The boost begins when H blocks at 4 ms and ends when L releases S at 10 ms. The boosted interval is 10 โ 4 = 6 ms; the earlier four milliseconds occurred before the inheritance condition arose.
Q11. A developer says priority inheritance guarantees that a waiting high-priority task immediately receives the resource, even when the owner must complete a long operation. Which correction is best?
๐ Explanation: The mistaken claim confuses a scheduling boost with resource release. Inheritance helps the owner run, but it cannot skip required operations, external waits, or other delays that must finish before release.
Q12. A chart gives medium-task execution time and H's measured blocking time as pairs: (0,4), (2,6), (4,8), (6,10), (8,12), with values in milliseconds. What is the increase in H's blocking time per additional millisecond of M execution?
๐ Explanation: Each two-millisecond increase in M execution raises H's blocking time by two milliseconds. The slope is therefore 2 รท 2 = 1, meaning each additional millisecond of M execution adds one millisecond of blocking.
Q13. A programmer assumes every semaphore in every operating system automatically boosts its owner when a higher-priority task waits. What is the accurate assessment?
๐ Explanation: Priority inheritance requires suitable ownership tracking and scheduler support. An ordinary semaphore does not universally provide it automatically, so developers must check the operating system, primitive type, and configured protocol.
Q14. L holds S and has base priority 3. Two tasks wait on S with priorities 6 and 9. Under a simple priority-inheritance model, what is L's effective priority?
๐ Explanation: The owner inherits the highest priority among the tasks blocked on the resource. Since the waiters have priorities 6 and 9, L's effective priority becomes 9 rather than the lower waiter's priority.
Q15. H waits for S held by L. L cannot continue because it waits for T held by K. With transitive priority inheritance, whose priority should be raised so the chain can progress?
๐ Explanation: L cannot finish its work on S until it obtains T from K. Propagating H's priority through the dependency chain helps K run, release T, and let L eventually release S for H.
Q16. L holds S and T. H at priority 10 waits on S, while M at priority 7 waits on T. L releases S but still holds T. What effective priority should L retain under basic inheritance bookkeeping?
๐ Explanation: Releasing S removes the inheritance contribution from H, but L still owns T while M waits at priority 7. L should therefore retain priority 7 until that remaining dependency also ends.
Q17. L holds S at base priority 2. H at priority 9 waits on S, then cancels its request; G at priority 7 is still waiting. What should a correct inheritance mechanism generally set as L's effective priority?
๐ Explanation: The priority boost from H is no longer needed after H cancels. Because G at priority 7 remains blocked on S, L should retain an effective priority of 7 rather than dropping to its base priority.
Q18. H blocks on S owned by L, but the kernel updates L's inherited priority only after an unrelated timer tick. What risk does this delayed update create?
๐ Explanation: Inheritance is useful when the owner receives the boost promptly after the higher-priority waiter blocks. A delayed update leaves L exposed to preemption in the meantime, allowing avoidable medium-priority execution to extend H's wait.
Q19. Timeline: L has base priority 2 and owns S; H at priority 9 blocks at t=1; G at priority 7 blocks at t=2; H cancels at t=5; G remains blocked until t=10. What should L's effective priority be at t=6?
๐ Explanation: At t=5, H's priority-9 wait ends, but G at priority 7 is still blocked on S. The highest remaining waiter determines the boost, so L's effective priority at t=6 should be 7.
Q20. L owns S and waits for a signal from H before releasing it. H cannot send that signal until it acquires S. What is the best diagnosis?
๐ Explanation: L waits for H's signal, while H waits for S owned by L. Raising L's priority cannot make H acquire the resource, so the circular dependency remains and the synchronization design must change.
Q21. A resource has a priority ceiling equal to the highest priority of any task that may use it. What does the ceiling value represent?
๐ Explanation: A priority ceiling is priority metadata derived from the tasks that may access a resource. It is not a permit count or a time limit; protocol rules use it to control scheduling around resource ownership.
Q22. Which statement best distinguishes priority inheritance from a priority-ceiling protocol?
๐ Explanation: Priority inheritance typically boosts an owner when a higher-priority task blocks on its resource. Ceiling protocols use preassigned resource ceilings and protocol-specific rules to constrain resource access and priority interactions.
Q23. Under an immediate-ceiling implementation, resource R has ceiling priority 9. Task L has base priority 2 and acquires R. What effective priority does L receive while holding R?
๐ Explanation: The scenario specifies an immediate-ceiling protocol, so acquiring R raises L to the resource's assigned ceiling. Its effective priority becomes 9 while the protocol requires that ceiling to apply throughout its ownership interval.
Q24. A student stores a resource ceiling of 8 by initializing its semaphore count to 8. Why is this implementation incorrect?
๐ Explanation: The flawed step treats two different values as interchangeable. A semaphore count represents permits or availability, while a priority ceiling represents a scheduling level used by a resource-access protocol within the kernel.
Q25. A team selects a priority-ceiling protocol for nested locks in a real-time controller. Which benefit is reasonable to expect under the protocol's assumptions?
๐ Explanation: Priority-ceiling protocols constrain resource acquisition and priority interactions. Under their required assumptions, they can bound blocking and prevent certain deadlock patterns, but they do not remove all execution delays or resource contention.
Q26. L holds a semaphore while performing unrelated logging and waiting for a network response. H needs the protected data. Which code change most directly reduces avoidable blocking?
๐ Explanation: Unrelated work lengthens the time the resource remains unavailable. Moving logging and external waits outside the critical section, while keeping shared-data access protected, reduces lock-hold time without introducing unsynchronized concurrent updates.
Q27. A team uses a binary semaphore for mutual exclusion and assumes this alone guarantees priority inheritance. Which implementation check is essential?
๐ Explanation: A binary count alone does not establish ownership-aware priority management. The team must verify that the selected primitive and kernel explicitly support priority inheritance, including the ownership and waiter tracking needed by the protocol.
Q28. L owns S and T. A priority-8 task waits on S, and a priority-10 task waits on T. Under a simple inheritance model, what effective priority should L have?
๐ Explanation: L owns both resources, so its effective priority must account for waiters on each owned resource. The highest relevant waiter has priority 10, which dominates the priority-8 waiter across all locks it owns.
Q29. A semaphore implementation supports priority inheritance, but after release it wakes a lower-priority waiter while a higher-priority waiter remains queued. What does this reveal?
๐ Explanation: Priority inheritance adjusts the owner's effective priority while waiters are blocked. It does not automatically define which waiter receives a released permit, so the wake-up policy must be examined separately.
Q30. An implementation tracks only the first task waiting on a semaphore. A later waiter has a higher priority. What is the likely failure?
๐ Explanation: The owner should reflect the highest relevant blocked priority, not merely the first waiter recorded. Missing a later, more urgent waiter can leave the owner under-boosted and extend that task's blocking interval.
Q31. A driver task holds S while waiting for a network packet, but the packet handler must acquire S to process that packet. Which correction best addresses the design flaw?
๐ Explanation: The driver cannot make progress until the packet arrives, while the packet handler cannot process it until S is free. This circular dependency is not solved by priority inheritance; the resource and event protocol must be redesigned.
Q32. A real-time task H needs 6 ms of CPU time and may be blocked for 7 ms by a lower-priority lock owner. Its deadline is 15 ms after release. Ignoring all other overhead, what is its remaining deadline slack?
๐ Explanation: The response-time budget used is execution plus blocking: 6 + 7 = 13 ms. With a 15 ms deadline, the remaining slack is 15 โ 13 = 2 ms, assuming no other delays or overhead.
Q33. H uses a priority-inheritance mutex, but its deadline is still missed because L performs a long, non-preemptible device operation while holding the mutex. What is the best conclusion?
๐ Explanation: Priority inheritance improves the owner's scheduling priority, but it cannot instantly finish a long device operation or make non-preemptible work interruptible. The remaining lock-hold duration must still be included in real-time analysis.
Q34. H at priority 10 waits on S owned by L at priority 2. L is itself blocked on T owned by K at priority 4, while M at priority 7 is ready. With transitive inheritance, which task must be boosted so the chain can first advance?
๐ Explanation: L cannot continue toward releasing S until K releases T. Transitive inheritance propagates H's urgency through L to K, allowing the deepest resource owner to run and release the resource needed by the chain.
Q35. Two tasks acquire resources R1 and R2 in opposite orders. A developer enables basic priority inheritance and claims deadlock is now impossible. Which assessment is correct?
๐ Explanation: Priority inheritance helps resource owners run but does not by itself change the order in which locks are requested. Opposite acquisition orders can still create circular wait and deadlock unless the locking protocol prevents it.
Q36. A trace shows L's base priority remains 2 throughout execution, while its effective priority rises to 9 only when H blocks on S, then returns to 2 after the dependency ends. Which interpretation is correct?
๐ Explanation: Priority inheritance normally adjusts the owner's effective scheduling priority while a higher-priority dependency exists. The base priority remains 2, and the temporary boost is removed when no applicable inheritance requirement remains.