Question: The following is alleged to be a solution to the critical section problem. Argue for its correctness or show a case in which it fails.
The following 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 variable to synchronize
operation */
boolean flag[2]; /* shared variable to synchronize
operation */
proc(int i){
while (TRUE) {
flag[i] = TRUE; /* Attempt to enter the critical
section */
turn = (i+1) mod 2;
while ((flag[(i+l) mod 2]) && (turn == (i+1) mod 2));
/* Now authorized to enter the critical section
/* Exiting the critical section */
flag[i] = FALSE;
}
}
turn = 0;
flag[0] = flag[1] = FALSE;
fork(proc, 1, 0); /* Start a process on proc(0) */
fork(proc, 1, 1); /* Start a process on proc(1) */
Step by Step Solution
3.37 Rating (169 Votes )
There are 3 Steps involved in it
This is Petersons software solution to the critical section problem The argument for its correctness is paraphrased from the original paper as follows ... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (1 attachment)
34-E-CE-OS (455).docx
120 KBs Word File
