GATE CSE · Operating Systems
Generate diverse GATE-level questions covering critical section problem, mutex, semaphores, monitors, and synchronization techniques.
Concept summary for GATE CSE 2027 · 62 practice questions available
Mechanisms to control the order of execution when processes share resources, to prevent race conditions and ensure data consistency.
When outcome depends on the order of execution of concurrent processes.
Example: counter++ is NOT atomic - it is read, increment, write (3 steps). Concurrent access corrupts value.
Requirements (must ALL hold):
Peterson's Solution (2 processes - Very Important):
// Process i (j = 1-i)
flag[i] = true;
turn = j;
while (flag[j] && turn == j); // busy wait
// critical section
flag[i] = false;
Satisfies all 3 conditions for 2 processes. Requires busy waiting. Assumes atomic load/store.
Integer variable S with two atomic operations:
Binary semaphore (mutex): S ∈ {0,1} - mutual exclusion
Counting semaphore: S = number of available resources - resource management
Semaphore for ordering (process B after process A):
Producer-Consumer (Bounded Buffer):
Readers-Writers:
Dining Philosophers:
High-level synchronization construct - only one process active inside monitor at a time.
Semaphore signal/wait order in producer-consumer: mutex must be INSIDE empty/full wait - reversing causes deadlock. Peterson's solution: memorize the flag and turn logic. Dining philosophers deadlock: all pick up one fork simultaneously - classic circular wait. Binary semaphore ≠ mutex in all implementations - binary semaphore can be signaled by any process, mutex must be released by acquirer.