Will deadlock happen when dealing with multiple semaphores?

When execute commands, will a queue hold a semaphore while waits on aonther semaphore?

For example I got two command buffers, both submitted with waiting on semaphore A and semaphore B, I got a feeling that deadlock will never happen, since semaphores work in GPU are different with mutex in CPU, the semaphore protects the hole command buffer, a command buffer will only require all semaphores or none, sort like a banker algorithm.

I’m I right about this? If not, in what case will a queue holds a semaphore and wait on aonther semaphore? Is there any pracitice to avoid semaphore deadlocks?

Queue Forward Progress chapter says when deadlocks could happen.

If both your waits compete for a single signal, then it can deadlock. Keep in mind that a wait is unsignal operation, and so after something waits on it, the semaphore changes state and would have to be signaled again before something can again wait on it.

1 Like