Bird
Raised Fist0

In a multithreaded application, which synchronization primitive should be used to allow up to N threads to access a shared resource simultaneously?

easy💻 Programming Q1 of Q15
Operating Systems - Semaphore vs Mutex - When to Use Which
In a multithreaded application, which synchronization primitive should be used to allow up to N threads to access a shared resource simultaneously?
ACondition variable
BMutex
CSpinlock
DCounting semaphore
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    Multiple threads can access the resource concurrently but limited to N.
  2. Step 2: Identify the primitive

    Counting semaphore allows controlling access to a fixed number of identical resources.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Counting semaphore controls multiple concurrent accesses [OK]
Quick Trick: Counting semaphore limits concurrent access by count [OK]
Common Mistakes:
MISTAKES
  • Choosing mutex which allows only one thread
  • Using spinlock which is for busy waiting
  • Condition variable is for signaling, not limiting access
Trap Explanation:
PITFALL
  • Mutex limits to one thread, not multiple concurrent accesses
Interviewer Note:
CONTEXT
  • Tests understanding of synchronization primitives for resource counting
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