edited by
2,024 views
8 votes
8 votes

Consider the following scheme for implementing a critical section in a situation with three processes $P_i, P_j$ and $P_k$.

Pi;

repeat
    flag[i] := true;
    while flag [j] or flag[k] do
        case turn of
        j: if flag [j] then
        begin
            flag [i] := false;
            while turn != i do skip;
            flag [i] := true;
        end;
        k: if flag [k] then
        begin
            flag [i] := false,
            while turn != i do skip;
            flag [i] := true
        end
    end
    critical section
    if turn = i then turn := j;
        flag [i] := false
    non-critical section
until false;

Is there a situation in which a waiting process can never enter the critical section? If so, explain and suggest modifications to the code to solve this problem

edited by

2 Answers

4 votes
4 votes

“the process which  use critical section should hold turn variable otherwise other waiting process will wait for indefinite time if some process does not wants to enter  in cs“
 

  1. progress not satisfied
    2. no deadlock 
edited by
1 votes
1 votes

Here 3 processes are there.

Now, at least 2 processes are ready to enter into CS at the same time

Here, as flag[i]=false // means flag[i] not ready to enter CS

So, Pj enters in CS

But CS depends on turn=i and turn=j and not on turn=k

So, if there is a situation turn=j is always false ,then Pk never go inside CS

edited by

Related questions

20 votes
20 votes
3 answers
2
Akash Kanase asked Apr 18, 2016
3,462 views
Consider the binary tree in the figure below:Give different steps for deleting the node with key $5$ so that the structure is preserved.
40 votes
40 votes
9 answers
4