Question: The following solution is alleged to be a solution to the critical section problem. Argue for its correctness or show a case in which it
The following solution is alleged to be a solution to the critical section problem. Argue for its correctness or show a case in which it fails.
shared int turn;
shared boolean flag[2];
proc(int i) {
while (TRUE) {
compute;
/* Attempt to enter the critical section */
try: flag[i] = TRUE; /* An atomic operation */
while (flag[(i+1) mod 2]) { /* An atomic operation */
if (turn = = i) continue;
flag[i] = FALSE;
while (turn != i);
goto try;
}
/* Okay to enter the critical section */
/* Leaving critical section */
turn = (i+1) mod 2;
flag[i] = FALSE;
}
}
turn = 0; /* process 0 wins a tie for the first turn */
flag[0] = flag[1] = FALSE;
/* Initialize flags before starting */
fork(proc, 1, 0); /* Create a process to run proc(0) */
fork(proc, 1, 1); /* Create a process to run proc(0) */
Step by Step Solution
3.38 Rating (160 Votes )
There are 3 Steps involved in it
This is Dekkers software solution to the critical section problem as published in Dijkstras original semaphore paper In the paper there is a proof of ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
34-E-CE-OS (450).docx
120 KBs Word File
