edited by
2,129 views
0 votes
0 votes

Clear Algorithm photo - here

Please see page 1 - here

Page 2 - here 

Page 3 here

My question is that when P0 didn't get stuck at line 11 on page 3 then won't it go and execute for loop? i.e make ++p and p will be made 1 and now P1 will also don't stuck at while loop at line 11 and now can enter Critical section with P0 and finally ++p again and P will made 2 and even P2 won't stuck at line 11 while as while loop will break and P2 also goes into CS?

Basically, how is the for loop working, here?

edited by

1 Answer

Best answer
2 votes
2 votes

i am simplifying the algorithm ( but it can't effect the output ) , In algorithm, the 11th line,  while(    ( num[p] != 0 ) && ( num[p],p ) <  ( num[i] , i )  )

should be as while(    ( num[p] != 0 ) && ( num[p] ) <  ( num[i] )  )

 

one more point we have to note down that

num[i]=Max( num[0], num[1],.... num[n-1] ) + 1

By this line we are allocating a minimum number to which process enter first, i.e., if P3 comes first it get value 1, next P1 comes it get value 2,..... due to this property we can ensure Bounded waiting.

 

 

i. for (p=0;p<N;p++){
ii.     while( choosing[p]  );
iii.      while( num[p]!=0 && (num[p] < num[i] ) );
}

 

every process have it's own lock ===> P0 have a copy of this for loop and P1 have it's own copy of this loop

while P0 only executing, remaining all are not interested, then P0 starts this for loop

1)   i) p=0, ii) break, iii) break

2)   i) p=1, ii) break, iii) break

3)  i) p=2, ii) break, iii) break 

4) i) p=3 therefore loop condition not satisfied exit from for loop

Finally P0 is entered into critical section.

 

now how p1 ( any process except P0 ) is entered? when there is P0 in Critical section.

now P1 comes..... ==> i=1 and note that num[P1] should be grater than num[P0]

for the first iteration of P1 :-

at line i), p=0

at line ii) : while( choosing[0] ) ====> False and loop exit

at line iii) :- while ( num[p] !=0 && ( num[p] < num[i] ) ) ===> while ( num[0] !=0 && ( num[0] < num[1] ) ) ===> while ( true && true ) ===> loop can't break ===> P1 Can't enter into CS 

selected by

Related questions

3 votes
3 votes
0 answers
1
iarnav asked Sep 28, 2018
720 views
Any implementation of a critical section requires the use of an indivisible machine- instruction ,such as test-and-set?Is the above statement True or False?