550 views
1 votes
1 votes

Shared Boolean waitIn [2] = false; 
Shared int turn = 1;  
int myPid = 0; // For process 0. Set to 1 for process 1 
int otherPid = 1 - myPid;  
wantIn [MyPid] = true;  
turn = OtherPid;  
while (wantIn [OtherPid] && turn == OtherPid);  
// Critical section  
wantIn [MyPid] = false; 

How to find the necessary condition for semaphore is satisfied?

1 Answer

0 votes
0 votes
it is the same implementation of peterson algorithm , just they have changed the turn = process , to turn = others process, the primary purpose of semaphore is to provide mutual exclusion which is definitely guaranteed.

No related questions found