Is Deadlock recovery possible in MultiThread programming?

The process has about 10 threads, and all 10 threads have entered the DEADLOCK state (suppose everyone is waiting for the Mutex variable).

How can you free the process (threads) from the DEADLOCK state ?, Is there a way to kill a thread with a lower priority? (In the case of multiple processes, we can kill a process with a lower priority when all processes are in a deadlock state).

Can we attach this deadlock process to the debugger and assign the correct value to the Mutex variable (suppose all threads are waiting for MUTEX MUTE, but this value is 0, and we can assign the value MUT 1 through the debugger).

+3
source share
2 answers

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. , , .

, , . , , . , " " (, ), " " (, ) . , , , , , .

+4

, -, . , - , - - , , , ( , - , , . , .) , .

:

  • , , -. , Java, synchronized lock, . , /, , .

  • , , , , . , . 10 , , , (.. , ) . , . , "" .

+5

Source: https://habr.com/ru/post/1767774/


All Articles