CS FundamentalsVery hardGATE CS
In Peterson's algorithm for P0 and P1, the entry code for Pi is `flag[i] = true; turn = j; while (flag[j] && turn == j);`. What goes wrong if the first two statements are swapped to `turn = j; flag[i] = true;`?
- A. Nothing, since the two writes are to different shared variables
- B. Mutual exclusion fails: both processes can be in the critical section
- C. Only progress fails: a process can wait although the other is outside
- D. Only bounded waiting fails; mutual exclusion still holds
Correct answer: B. Mutual exclusion fails: both processes can be in the critical section
P0 sets turn = 1; P1 sets turn = 0, flag[1] = true and enters since flag[0] is still false; P0 then sets flag[0] = true and finds turn == 0, so it enters too. The flag must be raised before yielding the turn.
More Operating Systems questions
- A counting semaphore is implemented WITHOUT busy waiting, and its value is −3 at some moment. What does this tell you?
- Which statement about user-level threads in a many-to-one model is correct?
- A system has 4 instances of R1 and 2 of R2. Allocated: P1 holds 1 R1; P2 holds 2 R1 and 1 R2; P3 holds 1 R1 and 1 R2. Requests: P1 wants 1…
- Which statement about a process that calls exec() successfully is correct?
- A logical address space has 8 pages of 2 KB each, and physical memory has 32 frames. How many bits are in a logical address and in a…
- Reference string 1, 2, 3, 1, 4, 5, 1, 6, 2, 1, 3, 4 with 3 frames, initially empty. The clock (second-chance) algorithm sets a page's…