4 basic methods to solve deadlock
1. Prevent deadlock: set some restrictions to destroy the factors that cause deadlock Necessary conditions
2. Avoid deadlock: During the resource allocation process, use some method to prevent the system from entering an unsafe state, thereby avoiding deadlock
3. Detect deadlock: Allow Deadlock occurs, but after passing the system detection, some measures are taken to clear the deadlock
4. Removing the deadlock: This method is used in conjunction with deadlock detection
Introduction to deadlock
Deadlock refers to a blocking phenomenon caused by two or more processes competing for resources or communicating with each other during execution. Without external force, None of them will be able to advance. At this time, the system is said to be in a deadlock state or the system has a deadlock. These processes that are always waiting for each other are called deadlock processes.
Generation conditions
Although a deadlock may occur during the running of the process, the occurrence of deadlock is also Certain conditions must be met. The following four necessary conditions must be met for deadlock to occur.
1) Mutual exclusion condition: refers to the exclusive use of allocated resources by a process, that is, a certain resource is only occupied by one process within a period of time. If there are other processes requesting resources at this time, the requester can only wait until the process occupying the resources is used up and released.
2) Request and hold conditions: It means that the process has held at least one resource, but has made a new resource request, and the resource has been occupied by other processes. At this time, the requesting process is blocked, but it has already requested the resource. Other resources obtained remain unchanged.
3) Non-deprivation condition: refers to the resource that the process has obtained. It cannot be deprived before it is used up, and can only be released by itself when it is used up.
4) Loop waiting condition: When a deadlock occurs, there must be a process-a circular chain of resources, that is, P0 in the process set {P0, P1, P2,···,Pn} Waiting for a resource occupied by P1; P1 is waiting for a resource occupied by P2,..., Pn is waiting for a resource occupied by P0.
Recommended tutorial: "MySQL Tutorial"
The above is the detailed content of 4 basic ways to solve deadlocks. For more information, please follow other related articles on the PHP Chinese website!