option d
Explanation:
Semaphore X=0;
Process 1 Process 2
Repeat Repeat
1. V(X) 1. P(X)
2. Compute; 2. Compute;
3. P(X) 3. V(X)
Forever Forever
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The process 1 is performing up() operation in step 1, whereas process 2 is performing down() operation.
Semaphore is initialized to 0;
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Both the process keeps on rotating because of forever loop.
- Definitely Process 2 can not enter as Down() operation at step 1;
- Process 1 will only enter and it will perform up() making X=1;
- As soon as X becomes 1 which is favourable for Process 2 to enter (remember it is still in continous rotaion will find X=1), it will enter or resume.
- Now Process 1 will Down() the semaphore and Process 2 will perform Up();