A CRITICAL SECTION is
Aany code that uses shared variables
Bcode accessing shared state that must run atomically
Ca section of code that runs only once at boot
Dthe smallest unit a compiler can optimise
Answer & Solution
Correct answer: B. code accessing shared state that must run atomically
1. OSTEP §26.1 defines: a critical section is a block of code that, when executed concurrently by multiple threads, can produce INCORRECT results unless serialised.
2. Example: incrementing a shared counter, adding to a linked list, updating a shared file pointer.
3. The classic protection: surround the critical section with `lock(L); ... unlock(L);`.
4. Not ALL code that uses shared variables is a critical section — code that only READS immutable shared state is safe without locks.
5. Options A, C, D describe broader or wrong concepts.
_Source: OSTEP Ch 26 (Concurrency: An Introduction), §26.1, 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$ tLinux'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 (wiA LOCK is considered FAIR if