The so-called deadlock: refers to two or more than two processes in the execution process, because of the contention for resources caused by a mutual waiting phenomenon, if there is no external force, they will not be able to proceed. At this point the system is in a deadlock state or the system generates a deadlock, and these processes, which are always waiting on each other, are called deadlock processes. because the resource consumption is mutually exclusive, when a process requests resources, so that the process without external assistance, never allocated the necessary resources and can not continue to run, which creates a special phenomenon of deadlock.
Although the process may occur during the operation of the deadlock, but the occurrence of deadlocks must also have certain conditions, the deadlock must have the following four necessary .
1 ) Mutex Condition:
Refers to the process of using the allocated resources for exclusive use, that is, for a period of time a resource is occupied by only one process. If there are other processes requesting resources at this time, the requestor can wait until the resource-occupying process is freed.
2 ) Request and hold condition:
means that the process has maintained at least one resource, but has made a new request for the resource that has been occupied by another process, at which point the request process is blocked, but the other resources that it has acquired remain.
3 ) Non-deprivation conditions:
refers to the resources that the process has acquired, cannot be deprived of until it is exhausted, and can only be released by itself when it is exhausted.
4 ) Loop wait Condition:
When a deadlock occurs, there must be a process--a circular chain of resources, that is, the process collection{P0,P1,P2,···,Pn}in theP0is waiting for aP1the resources occupied;P1is waitingP2the resources that are occupied,...,Pnis waiting to beP0the resource that is occupied.
After a deadlock has occurred in the system, the deadlock should be detected in time, and appropriate measures should be taken to remove the deadlock. The current method of handling deadlocks can be attributed to the following four types:
1) prevent deadlocks.
This is a simpler and more intuitive approach to proactive prevention. The method is to prevent deadlocks by setting certain constraints to destroy one or more of the four necessary conditions that produce deadlocks. The prevention of deadlocks is a more easily implemented method and has been widely used. However, due to the often restrictive conditions imposed, the system resource utilization and system throughput can be reduced.
2) avoid deadlocks.
This method is also a pre-prevention strategy, but it does not have to take a variety of restrictive measures to destroy the four necessary conditions for deadlocks, but in the dynamic allocation process of resources, in a way to prevent the system from entering the unsafe state, so as to avoid the deadlock.
3) detects deadlocks.
This method does not need to take any restrictive measures beforehand, nor does it have to check if the system has entered the unsafe zone, which allows the system to deadlock during operation. However, the detection mechanism set up by the system can detect the occurrence of the deadlock in time, and determine the process and resources related to the deadlock, then take appropriate measures to remove the deadlock from the system.
4) unlock the deadlock.
This is a measure to match the detection of deadlocks. When a deadlock has been detected in the system, the process must be freed from the deadlock state. A common practice is to undo or suspend some processes in order to reclaim some resources, and then assign those resources to a process that is already in a blocked state and make it ready to continue running. Deadlock detection and lifting measures, it is possible to make the system to achieve better resource utilization and throughput, but the implementation of the most difficult.
The conditions and preventive treatment of deadlock