Deadlock
In a multiprogramming system, multiple incoming programs execute concurrently, sharing system resources, thereby increasing resource utilization and system throughput, but a dangerous----deadlock may occur. The so-called deadlock, refers to a number of processes due to competitive resources, the formation of a deadlock, without external forces, these processes will never be able to further forward.
(1) causes and conditions for deadlocks
A, the reason for the birth and Death lock
The main reason for the death of the melt can be attributed to the following two points
(1) Competitive Resources
(2) process to advance the wrong order.
B, the necessary conditions for the birth and Death lock
(1) Mutually exclusive conditions
A resource can only be used by one process over a period of time, with exclusive sex.
(2) Request and retention conditions
When a process blocks when it requests a new resource, it remains on the resource that has been acquired.
(3) Non-deprivation of conditions
The resources that the process has acquired cannot be deprived until they are used, and can only be released by themselves when they are exhausted.
(4) Loop waiting condition
In the event of a deadlock, there must be a circular chain of processes--------resources. That is, the P1 in the process collection {P1,P2,...., Pn} is waiting for P2 to occupy resources, P2 is waiting for P3 to occupy resources,...., Pn is waiting for P1.
As long as the above 4 necessary conditions, the system will occur deadlock, as long as the above conditions are not satisfied, the system will not occur deadlock.
C, the method of dealing with deadlock
Because the occurrence of deadlock state will bring serious consequences to the whole system, so how to solve the deadlock problem has aroused people's widespread concern. There are three kinds of methods commonly used at present:
(1) Prevent deadlock
In order to keep the deadlock phenomenon in the system, it is necessary to select some restrictive conditions in the early stage of the system design to destroy one or several of the four essential conditions that produce deadlock. In this way, there will be no deadlock phenomenon in the system. This method is very effective in preventing deadlocks, but it may reduce the utilization of system resources.
(2) Avoid deadlock
Because on the one hand, the method of preventing deadlock will reduce the utilization of system resources, on the other hand, the necessary condition of deadlock is the existence of the system will cause deadlock, so in order to improve the utilization of system resources, can be used to avoid deadlock. To avoid deadlock does not strictly restrict the existence of deadlock conditions, but in the process of dynamic allocation of resources, some methods are used to prevent the system from entering into unsafe state, so as to avoid the tight final appearance of deadlock.
(3) Detect and unlock the deadlock
Because the probability of deadlock is always relatively small, in some relatively simple systems, in order to save the prevention or avoid deadlock in the increased overhead, the system allows the deadlock state. In this system, a special detection mechanism is set up, which can detect the occurrence of deadlock at any time, determine the process and resources associated with the deadlock, and then use the appropriate method to remove the deadlock status in the system.
There are two common ways to unlock a deadlock: one is to forcibly undo some deadlock processes and deprive their resources of other history; the other is to suspend a process by using a valid suspend and suspend mechanism to deprive some resources from the suspended process to unlock the deadlock.
Prevent deadlocks
(1) Break the "request and hold" condition
Break the request and hold condition, which means that all resources required to run the process are allocated to the process once before the process starts, and the process must wait for a resource that is not satisfied. In this way, the process will no longer need new resources during its operation, which is also known as the pre-static allocation method. The
(2) breaks the "Do not deprive" condition
and breaks the "do not deprive" condition by forcing those processes that request new resources without immediate gratification to release other resources that it has maintained. This means that a process can temporarily release the resources already in operation, that is, allowing other processes to deny the use of the resource, thereby undermining the "no deprivation" condition.
(3) When breaking the "loop wait" condition
deadlock occurs, there must be a loop chain of processes and resources. Breaking the "loop Wait" condition is the allocation of resources in the process of resource requests to make a certain limit, so that the loop can not appear.