Deadlock: Refers to two or more than two processes in the implementation process, as a result of contention for resources caused by a mutual wait for the phenomenon, without external forces, they will not be able to push down. It is said that the system is in a deadlock state or the system produces a deadlock, and these processes that are always waiting for each other are called deadlock processes. Because the resource occupation is mutually exclusive, when a process to apply for resources, so that the process without external assistance, can never allocate the necessary resources and can not continue to run, which creates a special phenomenon: deadlock. ”
Although a deadlock may occur while the process is running, a deadlock must have a certain condition, and the following four necessary conditions must exist for the deadlock to occur. 1 mutually exclusive conditions: refers to the process of allocating resources to the exclusive use, that is, for a period of time a resource is only occupied by a process. If there are other processes requesting resources at this time, the requester can only wait until the process that occupies the resource is released.
2 Request and Retention conditions: The process has maintained at least one resource, but a new resource request has been made, and the resource has been occupied by other processes, at which point the request process is blocked, but the other resources that it has obtained remain in place.
(3) No deprivation of condition: the resources that the process has obtained, which cannot be deprived until it has been used, can only be released by itself when the use is complete.
4) Loop waiting condition: In the event of a deadlock, there must be a process-a circular chain of resources, that is, the P0 in the process set {p0,p1,p2,,pn} is waiting for a P1 resource to occupy; P1 is waiting for the resources that P2 occupies, ..., and Pn is waiting for the resource that has been P0.
Understanding the causes of deadlocks, especially the four necessary conditions for deadlocks, is the most likely way to avoid, prevent, and unlock deadlocks. Therefore, in the system design, process scheduling and so on to pay attention to how to not let these four prerequisites, how to determine the rational allocation of resources algorithm, to avoid the process of permanent occupy the system resources. In addition, you want to prevent the process from consuming resources while it is in a waiting state. In the process of system operation, the process issued by each system can meet the resource request for dynamic check, and according to the inspection results to decide whether to allocate resources, if the system may occur after the allocation of deadlock, will not be allocated, otherwise allocated. Therefore, the allocation of resources should be given reasonable planning.
Ordered resource allocation method
This algorithm resource is numbered in a certain rule system (for example, the printer is 1, the tape drive is 2, the disk is 3, and so on), and the application must be in ascending order. System Requirements Request Process:
1. All resources that it must use and belong to the same category must be applied at once;
2, in the application of different types of resources, must be based on the number of various types of equipment to apply. For example: Process PA, the order of using resources is R1,R2, process PB, the order of using resources is R2,R1, if the dynamic allocation is possible to form loop conditions, resulting in deadlock.
Using ordered resource allocation method: R1 Number of 1,R2 is numbered 2;
PA: The order of application should be: R1,R2
PB: The order of application should be: R1,R2
This destroys the loop condition and avoids the deadlock.
Bank algorithm
The most representative algorithm for avoiding deadlock algorithms is the banker algorithm proposed by Dijkstra E.W in 1968:
The algorithm needs to check the applicant's maximum demand for resources, if the system's existing resources can meet the applicant's request, meet the applicant's request.
This allows the requester to quickly complete its calculations and then release the resources it occupies, thus ensuring that all processes in the system are complete, so that deadlocks can be avoided.
Live Lock (English livelock), refers to things 1 can use resources, but it let other things first use resources, things 2 can use resources, but it also let other things first use resources, so both have been humility, can not use resources.
Hunger, means that if the transaction T1 blocked the data R, the transaction T2 also request to block R, so T2 wait. T3 also requested to block R, when T1 released the blockade on R, the system first approved the T3 request, T2 still wait. T4 then asked to block R, and when T3 released the blockade on R, the system approved the T4 request ... T2 may wait forever, this is hunger. The
Live lock has a certain probability to unlock. The deadlock (deadlock) cannot be undone. An easy way to avoid living locks is to use first-come first-served policies. When multiple transaction requests block the same data object, the blocking subsystem queues the transaction in the order in which it is requested to block, and once the lock on the data object is released it approves the first transaction in the request queue to obtain the lock.