Bird
Raised Fist0

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:
  1. Step 1: Identify ownership semantics

    Mutex enforces ownership: only the thread that locks it can unlock it. Binary semaphores do not enforce ownership.
  2. 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.
  3. Final Answer:

    Option A -> Option A
  4. 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Operating Systems Quizzes