If the producer-consumer system is extended to support multiple buffers with different priorities, how should semaphore synchronization be adapted to ensure high-priority buffers are serviced first without causing starvation of lower-priority buffers?
hard🎤 Interviewer Follow-up Q10 of Q15
Operating Systems - Producer-Consumer Problem Using Semaphores
If the producer-consumer system is extended to support multiple buffers with different priorities, how should semaphore synchronization be adapted to ensure high-priority buffers are serviced first without causing starvation of lower-priority buffers?
AUse a single global semaphore and mutex for all buffers to simplify synchronization
BUse separate semaphores and mutexes per buffer and implement priority-aware semaphore acquisition with timeout and fallback
CUse busy waiting on high-priority buffers and blocking waits on low-priority buffers
DUse counting semaphores only on high-priority buffers and no synchronization on low-priority buffers
Step-by-Step Solution
Solution:
Step 1: Recognize need for per-buffer synchronization
Separate semaphores and mutexes per buffer allow independent control.
Step 2: Implement priority-aware acquisition
Priority-aware semaphore acquisition with timeout prevents starvation by allowing fallback to lower-priority buffers.
Step 3: Evaluate other options
Global semaphore (A) loses priority control; busy waiting (C) wastes CPU; no synchronization (D) risks data races.
Final Answer:
Option B -> Option B
Quick Check:
Priority-aware semaphores with fallback prevent starvation [OK]
Quick Trick:Priority-aware semaphore acquisition with fallback prevents starvation [OK]
Common Mistakes:
MISTAKES
Using global semaphore ignoring priorities
Busy waiting wastes CPU
Ignoring synchronization on low-priority buffers
Trap Explanation:
PITFALL
Candidates often oversimplify synchronization, missing starvation prevention in priority systems.
Interviewer Note:
CONTEXT
Tests advanced synchronization design and starvation avoidance.
Master "Producer-Consumer Problem Using Semaphores" in Operating Systems
2 interactive learning modes - each teaches the same concept differently