In which scenario is a mutex preferred over a binary semaphore for protecting a critical section?
easy🔍 Pattern Recognition Q2 of Q15
Operating Systems - Semaphore vs Mutex - When to Use Which
In which scenario is a mutex preferred over a binary semaphore for protecting a critical section?
AWhen ownership of the lock must be enforced so only the thread that locked it can unlock
BWhen multiple threads can enter the critical section simultaneously
CWhen the resource count needs to be tracked beyond binary states
DWhen the lock needs to be released by a different thread than the one that acquired it
Step-by-Step Solution
Solution:
Step 1: Identify ownership semantics
Mutex enforces ownership: only the thread that locks it can unlock it. Binary semaphores do not enforce ownership.
Step 2: Analyze options
Allowing multiple threads simultaneously (B) contradicts mutex purpose. Tracking resource count (C) is counting semaphore's role. Releasing lock by different thread (D) is allowed by semaphores but not mutexes.
Final Answer:
Option A -> Option A
Quick Check:
Mutex enforces ownership semantics strictly [OK]
Quick Trick:Mutex enforces ownership; binary semaphore does not [OK]
Common Mistakes:
MISTAKES
Assuming binary semaphore enforces ownership
Confusing mutex with counting semaphore for resource counts
Believing mutex allows unlocking by different threads
Trap Explanation:
PITFALL
Candidates often overlook ownership enforcement and think binary semaphores behave like mutexes in this regard.
Interviewer Note:
CONTEXT
Reveals understanding of ownership and release semantics in synchronization primitives.
Master "Semaphore vs Mutex - When to Use Which" in Operating Systems
2 interactive learning modes - each teaches the same concept differently