Home › GATE CSE › computerscience › Operating Systems › A LOCK (mutex) is used by concurrent threads to
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._
Related questions
On a MULTI-CORE system, a SPIN LOCK is generallyDisabling INTERRUPTS as a way to implement mutual exclusion on a single-CPU system isA LIVELOCK differs from a DEADLOCK in thatSuppose thread A acquires lock L1, then thread B acquires lock L2. Now A tries to acquire Without atomic hardware support, building a correct mutual-exclusion lock for $N \geq 2$ tA CRITICAL SECTION isLinux's `pthread_mutex_lock()` is typically implemented as a HYBRID:What is the PRIMARY problem with using a SPIN LOCK on a SINGLE-CPU uniprocessor system (wi