let S and Q to be initialized to 1

process p0:          process p1:

wait(S);             wait(Q);
wait(Q);             wait(S); 

..                    ..
..                    ..
Signal(S);           Signal(Q);
Signal(Q);           Signal(S);

I know there is a deadlock , where both the process will be going into the sleep , so what about starvation and bounded waiting?

My approach:

as only p0 can be executed any number of times i think there will be starvation and no bounded waiting.But answer is given that there is No Starvation.

  • $\begingroup$ I don't understand why "the answer" is "no starvation". Note that starvation freedom implies deadlock freedom. Since it suffers from deadlocks, it must also suffer from starvations. $\endgroup$
    – hengxin
    Dec 15, 2016 at 7:16
  • $\begingroup$ @hengxin you meant to say that if there is deadlock then that implies starvation? $\endgroup$ Dec 15, 2016 at 7:27
  • $\begingroup$ No starvation $\implies$ No deadlock. So deadlock $\implies$ starvation. $\endgroup$
    – hengxin
    Dec 15, 2016 at 7:31
  • $\begingroup$ i was thinking this way cs.stackexchange.com/questions/67406/… $\endgroup$ Dec 15, 2016 at 7:34

1 Answer 1


The answer is wrong.

Deadlock implies starvation, and the given code suffers from deadlock, here's how.

Say p0 executes wait(S); and then p1 executes wait(Q);. Now both the semaphores S and Q have value = 0.Now p0 will keep on waiting due to statement wait(Q); and p1 will keep on waiting due to statement wait(S);.

Freedom from starvation means that:

if a thread tries to acquire a lock , it will eventually succeed.

This does not happen here, so the answer is wrong.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.