Adding another answer, because I do not agree with the solutions proposed by cHao before - the analysis is in order.
Firstly, why I do not agree with the two proposed solutions:
Reduce conflict
The conflict does not lead to deadlocks. It just leads to poor performance. Deadlock means lack of productivity. Therefore, reduced competition does not allow deadlocks.
mutex timeout.
A mutex protects a resource, and a thread blocks a mutex because it needs a resource. With a timeout, you cannot receive the resource, and your thread will fail. Does it solve the deadlock problem? Only if the downstream thread releases another resource that blocks other threads.
. . , A, B, , A B, . : A B B C, , , A C.
. : , , A, B, , B. A , A B . A B.
; A, B, B, C, C, A, , . ; .
, . A B, A B. , , .
, , . , , . , " " (, ), " " (, ) . , , , , , .