Junior — Middle
Can a state of deadlock occur when using only one mutex?
sobes.tech AI
Answer from AI
Mutual deadlock occurs when two or more threads wait for each other, holding resources that others need. Using only one mutex, classic mutual deadlock is impossible because there is only one resource, and threads will just wait for it to be released.
However, a situation of self-deadlock can occur if a thread tries to re-acquire a mutex it already holds, and the mutex is not recursive. In this case, the thread will be blocked on itself.
In summary:
- Mutual deadlock between different threads with one mutex is impossible.
- Self-deadlock is possible if the mutex is non-recursive and the thread tries to acquire it again.