Dijkstra posed each of the following solutions as a potential software solution to the critical section problem
Question:
Dijkstra posed each of the following solutions as a potential software solution to the critical section problem and then explained why they failed [Dijkstra, 1968]. Provide your explanation about why they failed.
a. proc(int i) {
while (TRUE) {
compute;
while (turn != i);
critical_section;
turn = (i+1) mod 2;
}
}
shared int turn;
turn = 1;
fork(proc, 1, 0);
fork(proc, 1, 1);
b. proc(int i) {
while (TRUE) {
compute;
while (flag[(i+1) mod 2]);
flag[i] = TRUE;
critical_section;
flag[i] = FALSE;
}
}
shared boolean flag[2];
flag[0] = flag[1] = FALSE;
fork(proc, 1, 0);
fork(proc, 1, 1);
c. proc(int i) {
while (TRUE) {
compute;
flag[i] = TRUE;
while (flag[(i+1) mod 2]);
critical_section;
flag[i] = FALSE;
}
}
shared boolean flag[2];
flag[0] = flag[1] = FALSE;
fork(proc, 1, 0);
fork(proc, 1, 1);
Step by Step Answer: