The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
210 views

Given below is solution for the critical section problem of two processes $P_0$ and $P_1$ sharing the following variables:

var flag :array [0..1] of boolean; (initially false)
    turn: 0 .. 1;

The program below is for process Pi (i=0 or 1) where process Pj (j=1 or 0) being the other one.

repeat
        flag[i]:= true;
        while turn != i
        do begin
            while flag [j] do skip
            turn:=i;
        end
        
        critical section
        
        flag[i]:=false;
until false

Determine of the above solution is correct. If it is incorrect, demonstrate with an example how it violates the conditions.

asked in Operating System by Veteran (98.5k points) | 210 views

1 Answer

+1 vote

the above solution for critical section is'nt correct because it violates the condition of bounded wait. here is sample run

suppose turn =j;

Pi runs its first statement then Pj runs its first satement then Pi run 2,3,4 staement, It will block on statement 4

Now Pj start executing its statements goes to critical section and then flage[j]=false

Now suppose Pj comes again immediately after execution then it will again execute its critical section and then flag[j]=false

Now if Pj is coming continuously then process Pi will suffer starvation

answered by (27 points)


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

36,136 questions
43,587 answers
123,889 comments
42,832 users