-
Consider Peterson’s algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below.
repeat flag [i] = true;
turn = j;
while (P) do no-op;
Enter critical section, perform actions, then exit critical section
Flag [i] = false;
Perform other non-critical section actions. Until false;
For the program to guarantee mutual exclusion, the predicate P in the while loop should be
-
- flag [j] = true and turn = i
- flag [j] = true and turn = j
- flag [j] = true and turn = j
- flag [j] = true and turn = i
- flag [j] = true and turn = i
Correct Option: B
A mutual exclusion look is called mutex. In this two or more processes executes simultaneously and wait for the execution of another process. The process is called deadlock when two or more process simultaneously trying to enter a critical section, look each other out.
Let look at the simple algorithm for achieving the mutual exclusion between two processes with PID
equal to 0 or 1
int turn;
int interested [2];
void Get_Mutex (int pid)
{
int other;
other = 1-pid;
while (turn = = pid && interested [other])
{
}
}
release_mutex (int pid)
{
interested [pid] = false;
}
While loop if true predicate then the program enters into critical region. This program enters into critical region of flag [i]=true act as semaphore, & true =j, the requirement of resource is by some other process.
Hence (b) is correct option.