615 views

1 Answer

0 votes
0 votes

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;

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  1. Both the process keeps on rotating because of forever loop.
  2. Definitely Process 2 can not enter as Down() operation at step 1; 
  3. Process 1 will only enter and it will perform up() making X=1;
  4. 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.
  5. Now Process 1 will Down() the semaphore and Process 2 will perform Up(); 

Related questions

0 votes
0 votes
2 answers
2
shivajikobardan asked Jul 22, 2023
797 views
Sorry if this is a stupid question. But it really intrigued me. Same resources at different algorithms are telling different ways to test these stuffs.Here's an algorith...
1 votes
1 votes
2 answers
4