In: Computer Science
Answer:Option (A) - both mutual
exclusion for CS access and bounded-waiting for entry to
CS
Explanation:
Here we have two shared variables:
When a process wants to execute its critical section, it sets
its flag = true and turn as the
index of the other process. This means that the process wants to
execute but it will allow the other process to run first. The
process performs busy waiting until the other process has finished
its own critical section. If the process desires to acquire the
critical section, then, it gets the critical section and passes the
chance to the 2nd process. If it does not desire to get the
critical section then the while loop breaks and the 1st process
gets the chance.
Busy Waiting.
Flag[0]=TRUE; turn=1;
While (flag[1] && (turn==1)); // P1_gate
P0 and P1 can never be in the
critical section at the same time (MUTUAL EXCLUSION): If
P0 is in its critical section, then flag[0]
is true. In addition, either flag[1]
is
false
(meaning P1 has left its critical
section), or turn
is 0
(meaning
P1 is just now trying to enter the critical section, but
graciously waiting), or P1 is at the label
P1_gate
(trying to enter its critical section, after
setting flag[1]
to true
but before
setting turn
to 0
and busy waiting). So
if both processes are in their critical sections then we conclude
that the state must satisfy flag[0]
and
flag[1]
and turn = 0 and turn = 1. No state can
satisfy both turn = 0 and turn = 1
, so there can be no
state where both processes are in their critical
sections.
Bounded waiting says that a bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted.
Here, the Peterson's solution is considered strict alternation so, alternatively, process[0] and process[1] will get access to the critical section. Here bounded waiting won't be satisfied in case e.g. some process gets C.S. repeatedly starving other processes but this situation is not possible because of a strict alternation.
By using 'turn' variable bounded waiting is ensured.
Note:If you have any doubts or queries please comment I willget back to you and clarify.