CS FundamentalsVery hardGATE CS
In Lamport's bakery algorithm, why does a process pick a number with `number[i] = max(number) + 1` while choosing[i] is true, and break ties by process ID?
- A. Because max() is atomic in hardware
- B. Because numbers are always distinct, the ID is only for logging
- C. Two processes can read the same max concurrently and get equal numbers, so ties must be broken by ID, and choosing[] prevents comparing against a half-written number
- D. Because choosing[] implements a spinlock around max()
Correct answer: C. Two processes can read the same max concurrently and get equal numbers, so ties must be broken by ID, and choosing[] prevents comparing against a half-written number
Taking a ticket is not atomic, so equal tickets are possible; ordering by (number, id) makes the order total. The choosing flag makes others wait until a process's ticket is fully written before comparing.
More Operating Systems questions
- A barrier for N threads is implemented with count (protected by mutex) and a semaphore barrier = 0: each thread does lock; count++; if…
- Processes (arrival, burst): P1 (0, 12), P2 (2, 4), P3 (3, 6), P4 (8, 5), P5 (10, 2). Under SRTF, which process waits the longest, and for…
- Processes (arrival, burst): A (0, 5), B (1, 7), C (3, 2), D (4, 6). Round Robin with quantum 4 (new arrivals queued before a preempted…
- Processes (arrival, burst, priority; smaller number = higher priority): P1 (0, 3, 2), P2 (1, 6, 1), P3 (2, 4, 3), P4 (12, 2, 1), P5 (13…
- Processes (arrival, burst): A (0, 6), B (2, 6), C (5, 9), D (5, 8), E (5, 2). Under non-preemptive HRRN, what is the average waiting time?
- Two processes each alternate CPU and I/O: P1 = CPU 4, I/O 6, CPU 2; P2 = CPU 3, I/O 3, CPU 5 (ms). Both arrive at 0, P1 first; scheduling…