CS FundamentalsHardGATE CS
Strict alternation uses a shared turn variable: P0: `while (turn != 0); CS; turn = 1;` P1: `while (turn != 1); CS; turn = 0;`. P0 wants to enter its critical section twice in a row while P1 is busy in a long remainder section. What happens?
- A. P0 enters twice; mutual exclusion is violated
- B. Both deadlock immediately
- C. P0 blocks after its first entry until P1 enters and leaves its own critical section, violating progress
- D. P0 enters twice with no waiting
Correct answer: C. P0 blocks after its first entry until P1 enters and leaves its own critical section, violating progress
After P0 sets turn = 1, only P1 may enter next. P1, not interested, holds up P0 from its remainder section: this violates progress, though mutual exclusion holds.
More Operating Systems questions
- Two processes each run flag[i] = true; while (flag[j]); CS; flag[i] = false; (no turn variable). Which statement is correct?
- Two processes each run while (flag[j]); flag[i] = true; CS; flag[i] = false; (check first, then set). Which property fails?
- Peterson's algorithm is written with turn = i; (giving the turn to ITSELF) instead of turn = j;: flag[i] = true; turn = i; while (flag[j]…
- stdout is a pipe (fully buffered) and every fork() succeeds. What is the complete output, up to the order of the lines? c int main() {…
- How many times is "x" printed? (Every fork() succeeds; output unbuffered.) c int main() { for (int i = 0; i < 2; i++) { if (fork() == 0)…
- What values are printed (in any order)? (Every fork() succeeds.) c int main() { int x = 1; if (fork() == 0) { x = 2; if (fork() == 0) x =…