Bird
Raised Fist0

Why is it generally not advisable to use a counting semaphore as a mutex replacement for protecting a critical section?

medium🪤 Complexity Trap Q13 of Q15
Operating Systems - Semaphore vs Mutex - When to Use Which
Why is it generally not advisable to use a counting semaphore as a mutex replacement for protecting a critical section?
ABecause counting semaphores do not enforce ownership, leading to potential release by non-owner threads
BBecause counting semaphores have higher overhead due to maintaining a count variable
CBecause counting semaphores cannot block threads when the count is zero
DBecause counting semaphores allow only one thread at a time, making them equivalent to mutexes
Step-by-Step Solution
  1. Step 1: Understand mutex ownership

    Mutex enforces strict ownership; only the locking thread can unlock.
  2. Step 2: Counting semaphore behavior

    Counting semaphores track resource count but do not enforce ownership.
  3. Step 3: Consequences of no ownership

    Any thread can signal (release) the semaphore, risking synchronization errors.
  4. Step 4: Why other options are incorrect

    B is true but not the main reason; C is false--semaphores do block; D is false--counting semaphores allow multiple threads.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Ownership enforcement is key difference; counting semaphores lack it.
Quick Trick: Mutex ownership vs semaphore count: ownership prevents misuse.
Common Mistakes:
MISTAKES
  • Confusing blocking behavior of semaphores
  • Assuming counting semaphore overhead is prohibitive
  • Believing counting semaphore is equivalent to mutex
Trap Explanation:
PITFALL
  • Candidates often focus on performance or blocking behavior, missing the critical ownership enforcement difference.
Interviewer Note:
CONTEXT
  • Tests understanding of ownership semantics and why mutexes are preferred for critical sections.
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