๐ŸŽ“ BookMCQ
โ† Back to 5. Process Synchronization

๐Ÿ“ 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.
12
Easy
12
Medium
12
Hard

๐Ÿ“ 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?

A.Priority inheritance
B.Priority inversion โœ…
C.Circular wait
D.Semaphore starvation
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– 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?

A.M has secretly acquired S
B.H must wait for every runnable task
C.M preempts L, the owner whose release of S is required by H โœ…
D.M changes the semaphore count without executing a semaphore operation
๐Ÿ’ก Difficulty: easy | โœ… Correct: C

๐Ÿ“– 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?

A.3 ms
B.7 ms
C.10 ms โœ…
D.12 ms
๐Ÿ’ก Difficulty: easy | โœ… Correct: C

๐Ÿ“– 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?

A.H is blocked and cannot use a higher priority to take a semaphore held by L โœ…
B.The scheduler always lowers H after a wait
C.A semaphore owner cannot ever be preempted
D.Priority values do not affect task scheduling
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– 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?

A.2
B.6
C.8
D.10 โœ…
๐Ÿ’ก Difficulty: easy | โœ… Correct: D

๐Ÿ“– 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?

A.The semaphore has gained extra permits
B.The high-priority task is executing in parallel
C.The low-priority owner has permanently changed its base priority
D.The blocking time depends on scheduling activity unrelated to the protected resource โœ…
๐Ÿ’ก Difficulty: easy | โœ… Correct: D

๐Ÿ“– 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?

A.It removes the 5 ms of required work
B.It guarantees that H executes inside L's critical section
C.It helps L receive CPU time sooner but does not remove the protected work itself โœ…
D.It releases the mutex as soon as H requests it
๐Ÿ’ก Difficulty: easy | โœ… Correct: C

๐Ÿ“– 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?

A.Polling automatically transfers ownership to H
B.H can consume processor time that L needs to finish and release S โœ…
C.Polling forces M to inherit H's priority
D.A busy-wait loop makes the critical section shorter
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– 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?

A.4 ms
B.11 ms โœ…
C.7 ms
D.15 ms
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– 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?

A.6 ms โœ…
B.4 ms
C.9 ms
D.10 ms
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– 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?

A.Inheritance removes all critical-section execution time
B.The waiting task executes the owner's remaining instructions
C.The resource is released automatically when priorities change
D.Inheritance can reduce preemption delays, but the owner must still finish the work needed to release the resource โœ…
๐Ÿ’ก Difficulty: easy | โœ… Correct: D

๐Ÿ“– 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?

A.0.5 ms
B.1 ms โœ…
C.2 ms
D.4 ms
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– 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?

A.All semaphores inherit priority by definition
B.Inheritance depends on support in the synchronization primitive and its configuration โœ…
C.Only counting semaphores can inherit priority
D.The scheduler infers ownership from the semaphore count alone
๐Ÿ’ก Difficulty: medium | โœ… Correct: B

๐Ÿ“– 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?

A.3
B.6
C.8
D.9 โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– 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?

A.Only H, because it is the highest-priority task
B.M, even though M owns neither resource
C.K, so it can release T and allow L to release S โœ…
D.No owner; transitive inheritance is not used for nested locks
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.7 โœ…
B.10
C.3
D.1
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– 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?

A.9 until L releases every semaphore
B.2 immediately, even though G remains blocked
C.7, reflecting the highest remaining waiter โœ…
D.5, the average of the waiter priorities
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.L may remain at low priority long enough for medium-priority work to extend H's blocking โœ…
B.H gains ownership of S during the delay
C.The semaphore count must become equal to the timer period
D.M is prevented from becoming runnable
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– 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?

A.2
B.5
C.7 โœ…
D.9
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.Priority inheritance alone resolves the dependency
B.This is a logical circular dependency that requires redesign of the event or lock ordering โœ…
C.Raising H's priority lets it acquire S while blocked
D.The semaphore should be changed to a larger count without changing the protocol
๐Ÿ’ก Difficulty: medium | โœ… Correct: B

๐Ÿ“– 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?

A.The maximum number of semaphore permits
B.The longest time a task may hold the resource
C.The highest resource-related priority assigned by the protocol โœ…
D.The number of waiting tasks allowed in the queue
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.Inheritance reacts to a higher-priority waiter, whereas ceiling protocols use priorities assigned to resources and additional access rules โœ…
B.Inheritance changes semaphore counts, whereas ceiling protocols change CPU speed
C.Inheritance is only for counting semaphores, whereas ceiling is only for binary semaphores
D.Both guarantee that resource blocking never occurs
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– 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?

A.2
B.5
C.7
D.9 โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– 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?

A.A ceiling is priority metadata, not the number of available permits โœ…
B.Every semaphore count must equal the owner's base priority
C.A resource ceiling must always be zero
D.Semaphore counts cannot be represented as integers
๐Ÿ’ก Difficulty: medium | โœ… Correct: A

๐Ÿ“– 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?

A.All execution-time variation disappears
B.Every task can enter every critical section concurrently
C.Certain blocking patterns can be bounded and some deadlock patterns prevented โœ…
D.No task ever waits for a shared resource
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.Move unrelated logging and network waiting outside the protected region when correctness permits โœ…
B.Increase H's priority repeatedly
C.Remove all synchronization around the shared data
D.Keep the semaphore locked until the entire task terminates
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– 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?

A.Whether the semaphore count can store the task identifier
B.Whether the primitive tracks ownership and explicitly supports the required inheritance protocol โœ…
C.Whether the protected object is larger than one page
D.Whether all tasks have different names
๐Ÿ’ก Difficulty: hard | โœ… Correct: B

๐Ÿ“– 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?

A.8
B.9
C.10 โœ…
D.18
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.Inheritance necessarily orders the wait queue by priority
B.Wake-up selection is separate from owner priority inheritance, so urgent waiters may still be delayed โœ…
C.The released semaphore has become a mutex
D.The highest-priority waiter has already acquired the resource
๐Ÿ’ก Difficulty: hard | โœ… Correct: B

๐Ÿ“– 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?

A.The owner may inherit too low a priority and remain vulnerable to preemption โœ…
B.The first waiter must become the semaphore owner immediately
C.The semaphore becomes a counting semaphore
D.The later waiter automatically loses its priority
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– 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?

A.Raise the driver priority to the maximum value
B.Keep S locked until the packet timeout expires
C.Change the event and lock ordering so the packet handler does not need a resource held by the waiting driver โœ…
D.Make the packet handler busy-wait on S
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.0 ms
B.1 ms
C.2 ms โœ…
D.7 ms
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.Inheritance guarantees every deadline regardless of critical-section behavior
B.H must actually have a lower base priority than L
C.The mutex count should be increased
D.Inheritance limits some preemption delays but cannot eliminate long protected or non-preemptible operations โœ…
๐Ÿ’ก Difficulty: hard | โœ… Correct: D

๐Ÿ“– 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?

A.H, because it is already blocked
B.M, because it is currently ready
C.K, the owner of T that prevents L from progressing โœ…
D.No task; inheritance cannot propagate through nested locks
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.Correct; inheritance always breaks circular wait
B.Incorrect; inheritance changes scheduling priority but does not necessarily remove a circular resource dependency โœ…
C.Correct; inherited tasks can acquire locks they do not own
D.Incorrect only when both resources are counting semaphores
๐Ÿ’ก Difficulty: hard | โœ… Correct: B

๐Ÿ“– 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?

A.L's base priority was permanently changed twice
B.The scheduler has ignored H's blocked state
C.The semaphore count has become the effective priority
D.Priority inheritance temporarily changed L's effective priority without changing its base priority โœ…
๐Ÿ’ก Difficulty: hard | โœ… Correct: D

๐Ÿ“– 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.

๐Ÿ”— Related Topics (MCQs)