I was doing operating systems in which there was a topic of turn variable well there are two processes P0,P1 and int turn =0
For Process P0 For Process P1
Non Critical Section Non Critical Section
while(turn!=0) while(turn!=1)
//enter critical section //enter critical section
turn=1; turn=0;
Non Critical Section Non Critical Section
Now these are two pseudo codes for two processes so if variable turn initial value is 0 then according to you which process will get into critical section first.Is it P0 or P1??
According to me
Like i m getting confused as if turn=0 then if it enters while loop
while(0 !=0 ) since condition doesnot match false it will leave for P0 and not enter critical section
while(0 !=1 ) since condition is true so P1 will get a chance to enter critical section according to me
According to book
But in the book P0 was getting first so why it is so that P0 get a chance to enter first and then P1 got chance to enter
Please somebody tell me correct ans to this problem.I am really stuck and confused