Difficulty: Easy
Correct Answer: synchronize critical resources to prevent contention
Explanation:
Introduction / Context:
Semaphores are classic synchronization primitives used in operating systems and concurrent programming to coordinate access to shared data. They help ensure that only a safe number of processes or threads enter a critical section at once, thereby avoiding race conditions and data corruption. This question tests your understanding of the core purpose of semaphores.
Given Data / Assumptions:
Concept / Approach:
A binary semaphore (value 0 or 1) enforces mutual exclusion; a counting semaphore controls access to a limited resource with capacity greater than one. Their goal is to prevent contention (simultaneous, unsafe access), which in turn prevents race conditions. While semaphores can be used in protocols that avoid deadlocks, their mere presence does not automatically prevent all deadlocks—it depends on how they are used.
Step-by-Step Solution:
Verification / Alternative check:
Standard OS texts present semaphore-based mutual exclusion and producer–consumer solutions where contention is controlled by semaphore counters; deadlock avoidance requires additional policy (ordering, timeouts, or detection).
Why Other Options Are Wrong:
Common Pitfalls:
Assuming semaphores automatically eliminate deadlock; forgetting to signal, which can cause starvation; using multiple semaphores in inconsistent order leading to deadlock.
Final Answer:
synchronize critical resources to prevent contention
Discussion & Comments