The following is a code with two threads, producer and consumer, that can run…

PYQ GATE 2008

The following is a 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;
integer x;

producer:

consumer:

while (true) do

while (true) do

P(S);

P(Q);

x = produce();

consume(x);

V(Q);

V(S);

done

done

Which of the following is TRUE about the program above?

  1. A.

    The process can deadlock

  2. B.

    One of the threads can starve

  3. C.

    Some of the items produced by the producer may be lost

  4. D.

    Values generated and stored in 'x' by the producer will always be consumed before the producer can generate a new value

Attempted by 281 students.

Sign up free to check your answer

Sign up free

Explore the full course: Zero To Hero

Loading lesson…