CS FundamentalsHardGATE CS
Two processes each run `flag[i] = true; while (flag[j]); CS; flag[i] = false;` (no turn variable). Which statement is correct?
- A. Mutual exclusion can be violated
- B. It satisfies all three requirements
- C. Only bounded waiting fails
- D. Mutual exclusion holds, but both can set their flags and then wait forever (deadlock)
Correct answer: D. Mutual exclusion holds, but both can set their flags and then wait forever (deadlock)
Once a process passes the loop, the other's flag was false at that point and its own flag blocks the other. But if both set flag = true before checking, both spin forever.
More Operating Systems questions
- 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 =…
- How many processes are created in total, including the original? (Every fork() succeeds.) c int main() { for (int i = 0; i < 3; i++) if…