1. The concept of deadlock
If the synchronization of multiple threads is not designed properly, it will cause deadlock. Deadlock refers to a situation where multiple threads share certain resources and are waiting for each other to release the resources, causing the program to stagnate.
Deadlock will cause the program to stagnate, so we must pay attention to avoid deadlock when writing multi-threaded programs. In fact, the above problem is easy to solve, as long as the two threads access critical resources in the same order. Set the lock timeout. This method can also be used to avoid deadlock
2. Deadlock conditions
Mutual exclusion conditions: Resources cannot be shared, only Used by a process.
Request and retention conditions: A process that has obtained resources can apply for new resources again.
Non-deprivation condition: Already allocated resources cannot be forcibly deprived from the corresponding process.
Loop waiting conditions: Several processes in the system form a loop, and each process in the loop is waiting for the resources occupied by adjacent processes.
The above is the detailed content of The concept of deadlock and the conditions of deadlock. For more information, please follow other related articles on the PHP Chinese website!