A LOCK (mutex) is used by concurrent threads to
Aincrease the speed of single-threaded code
Bavoid the need for any context switches
Cautomatically detect deadlocks at runtime
Densure mutual exclusion in a critical section
Answer & Solution
Correct answer: D. ensure mutual exclusion in a critical section
1. OSTEP §28.1 defines locks: a synchronisation primitive used to enforce MUTUAL EXCLUSION around a CRITICAL SECTION.
2. Usage pattern: `lock(L); // critical section ... unlock(L);`. Only one thread holds the lock at a time; others wait.
3. Mutual exclusion ensures that race conditions inside the critical section cannot corrupt shared state.
4. Options A, C, D misstate the purpose. Locks do NOT speed up single-threaded code, avoid context switches, or detect deadlocks.
_Source: OSTEP Ch 28 "Locks", §28.1 (Locks: The Basic Idea), p. 1-2._
Keep practising Operating Systems
Browse all Operating Systems questions for GATE CSE, or explore more Computer Science topics.
Related questions
On a MULTI-CORE system, a SPIN LOCK is generallyA LIVELOCK differs from a DEADLOCK in thatSuppose thread A acquires lock L1, then thread B acquires lock L2. Now A tries to acquire A CRITICAL SECTION isA LOCK is considered FAIR ifWhich of the following is NOT typically minimised by a CPU scheduler?The PRIMARY DISADVANTAGE of FIFO scheduling isJobs A (run time 100, arrival 0), B (run time 10, arrival 0), C (run time 10, arrival 0) u