Dijkstra posed each of the following solutions as a potential software solution
ID: 3686253 • Letter: D
Question
Dijkstra posed each of the following solutions as a potential software solution o the critical section problem and then explained why they failed. Provide your explanation about why they filed.
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)
Explanation / Answer
Not sure with (1) any help please comment
2)
If one process does "flag[i] = TRUE", then gets interrupted immediately afterwards and the other one does the same thing, then both of them will block at "while(flag[(i+1) mod 2]", violating Starvation.
3)
"while(flag[(i+1)mod2])", gets interrupted immediately afterwards, then the other process does the same thing, then they both go on to do “flag[i]=TRUE” and enter their critical sections at the same time, violating Mutual Exclusion.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.