As semaphore mechanism uses two queues:

  • Block queue
  • Ready queue

In two possible cases:

If ①the signal of semaphore is negative (considerably large),

②an essential process which provides required resources is blocked, will there be deadlock?


For example, we have three processes in block queue but the signal is negative five (s = -5), will the processes forever blocked in the queue?

In the second case, if process P1, P2, P3 relies on results of P4, and P4 is blocked in a queue (is it possible?), so is there nothing we can do to increase semaphore by semSignal(), indicating a deadlock?

有帮助吗?

解决方案

For example, we have three processes in block queue but the signal is negative five (s = -5), will the processes forever blocked in the queue?

If you accept the concept of semaphore counts becoming negative, ie. negative values represent the number of waiting threads, the count could not become -5 if there are only three threads waiting. If that happens, your semaphore implementation is borked.

In the second case, if process P1, P2, P3 relies on results of P4, and P4 is blocked in a queue (is it possible?), so is there nothing we can do to increase semaphore by semSignal(), indicating a deadlock?

I do not understand this scenario. It does not describe a deadlock. If P4 is stuck on some queue, and that is the reason why the four thread cannot make forward progress because they are all blocked, then you should work out why P4 got stuck in the first place.

A deadlock might occur if P4 is waiting for some signal from p1, p2 and/or p3.

Shoving in extra semaphore units to attempt to escape a deadlock would be, in all the cases I can think of, a band-aid on a leaking nuclear reactor.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top