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