It is not explicitly given that it is a counting semaphore, but its intituitive.
option C says that “when buffer is empty” this means two things→
- The first operation is consume.
- Equal number of produce and consume has been performed and now the buffer is empty and we are consuming again.
If we simulate consumer(), when the buffer is empty,
semWait(s) → s=0
(means the next time we do semWait(s) the value of s will become <0 and the process will be put to sleep, however s=0 as of now so we can continue our execution)
semWait(n) → n=-1
(means the value of n has become <0 so we need to put consumer process to sleep)
Switching over to producer we encounter,
serWait(s) → s=-1
(since s<0 we must put the producer to sleep)
Both the producer and consumer are blocked so it is a Deadlock.