211 views
0 votes
0 votes

The following is the code with two threads, producer and consumer, that can run in parallel. Further, S and Q are binary semaphores equipped with the standard P and V operations.


semaphore S=1,Q=0
int x;
Producer:

while(true) do

     P(S);

           x=produce();

     v(Q);
     done for producer.

Consumer:

 while(true) do

      P(Q);

      consume(x);

      V(S);
      done for the consumer.
which of the following statements is true about the program above?

  1. The process can deadlock.
  1. One of the threads can starve.
  1. Some of the produced items by the producer may lost.
  1. Values generated and stored in ‘x’ by the producer will always be consumed before the producer can generate a new value.

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
1
Nam14 asked Apr 5, 2023
536 views
Please read below passage from 10th edition Operating System Concepts, pg. 202:5.1.3 Preemptive and Nonpreemptive SchedulingCPU-scheduling decisions may take place under ...
0 votes
0 votes
0 answers
2
Iamniks4 asked Jan 16, 2019
232 views
Caption
0 votes
0 votes
1 answer
3
Dhiraj Raj asked Dec 5, 2018
780 views
The Process which are in Blocked Suspended State or In Ready Suspended State, where that Process lies, in Main Memory or Disk ?