The fundamental way to prevent deadlocks is to make one of the 4 necessary conditions that a deadlock does not exist. Here's an analysis of the possibility of breaking these conditions.
Breaking mutually exclusive conditions
Breaking mutually exclusive conditions allows multiple processes to access resources concurrently. Because the inherent nature of most resources must be mutually exclusive access cannot be changed, the prevention of deadlock is not feasible in many cases by destroying this necessary condition. For example, printer resources must be mutually exclusive, otherwise several processes are used at the same time, each process printing a row, the way the output information is clearly not acceptable to the user.
Destruction of possession and waiting conditions
The use of resource static allocation method can destroy this condition, which means that before the process runs, once _ please allocate all the resources it needs to run. If the system has enough resources to allocate to a process, it assigns the required resources to the process at once, so that no resource requests are made during the process, making the wait condition not valid. If one of the resource requirements is not met at the time of allocation, the other resources required by the process are not assigned to the process, thereby preventing the process from taking up any resources during the wait, destroying the occupancy condition, and thus avoiding the deadlock.
The method is simple and easy to implement, however, due to the full use of the required resources during the process, some of the resources that have been used for a short period of time are occupied for a long time, which can seriously affect the full utilization of the system resources, resulting in lower resource utilization and the same inch affecting the process of not getting all the resources.
Destroy the condition of not being deprived
The use of a deprivation control method can destroy the condition by enabling a process that has maintained certain resources, since the new resource requirements are currently not met, it must first temporarily release all the resources that have been maintained (a kind of deprivation), and then go to wait, and then together to the system to put towel please, this can also prevent deadlock. This approach is relatively difficult to achieve, in order to protect the process to automatically discard the resources of the site and subsequent recovery, the need to pay a high price, and this method is only applicable to the processor and memory resources, other resources, this method is not suitable for use.
Destroy the loop wait condition
This condition can be destroyed by using the resource order distribution method. The basic idea of this method of distribution is to divide the whole resources of the system into multiple levels, once a process gets a resource from a layer, it can only ask for a higher level of resources; When a process releases a resource from a layer, it must first release the higher level of resources it occupies; When a process obtains a resource from a layer, It wants to apply for another resource in that layer, and it must first release the resources that have been in that layer. Alternatively, the order in which the processes release resources is in the reverse order of the resources requested in. This prevents the cycle-waiting phenomenon from occurring and therefore does not result in deadlocks. The problem that should be paid special attention to in using this method is the arrangement of the level of resources. In general, the more general resources that are often used in the processes are arranged at a lower level, with important and relatively scarce resources placed at a higher level in order to maximize the use of resources. Compared with the methods described earlier, the method has a significant improvement in resource utilization and system throughput. But there are some flaws.
(1) Low-level resources must be requested before the process requests the allocation of Gao resources, which can be wasted on idle waiting for low-level resources that are temporarily unused.
(2) The level of resources of various types of equipment, once set, can not be arbitrarily changed, which limits the increase of new types of equipment.
(3) The level of each resource is set in the order in which most processes use resources. Resources can be used effectively in the process of using resources to flash with this level, otherwise, the waste of resources will still exist.