First, the concept of deadlock
Synchronization of multiple threads can cause deadlocks if they are poorly designed. A deadlock is when multiple threads share certain resources while waiting for the other to release resources, causing the program to stagnate.
Deadlock can cause the program to stall, so we must be careful to avoid deadlocks when we write multi-threaded programs. In fact, the above problem is well solved, as long as two threads access critical resources in the same order. Set the lock timeout, which can also be used to avoid deadlocks
Ii. conditions of the deadlock
Mutex condition: A resource cannot be shared and can only be used by one process.
Request and hold condition: a process that has been given a resource can request a new resource again.
Non-deprivation: the resources already allocated cannot be forcibly deprived from the corresponding process.
Cyclic wait condition: Several processes in the system make up loops, and each process in the loop is waiting for the resources that the neighboring process is occupying.