The main causes of deadlocks are :
(1) Due to insufficient system resources.
(2) The sequence of progress of the process is not appropriate.
(3) Improper allocation of resources and so on.
If the system resources are sufficient, the resource request of the process can be satisfied, the probability of deadlock is very low, otherwise
will be locked into a deadlock over a limited resource. Second, the process is run in a different order and speed, and may also produce a deadlock.
The four necessary conditions for creating a deadlock:
The 4 necessary conditions for a deadlock:
(1) Mutex condition (Mutual exclusion): A resource cannot be shared and can only be used by one process.
(2) Request and maintain conditions (hold and wait): a process that has already received a resource can request a new resource again.
(3) Non-deprivation conditions (no pre-emption): The allocated resources cannot be forcibly deprived from the corresponding process.
(4) Cyclic wait condition (Circular wait): Several processes in the system make up loops that each process in the loop waits for resources that are being consumed by the neighboring process.
These four conditions are necessary for the deadlock, as long as the system has a deadlock, these conditions must be established, and as long as one of the above conditions is not satisfied, there will be no deadlock.
Release and prevention of deadlocks:
1. Ignore the problem. For example, the ostrich algorithm, the algorithm can be applied in the case of very few deadlocks occur.
Why is called the ostrich algorithm, because the legend of the ostrich saw the danger of burying his head under the ground, perhaps the ostrich feel that there is no danger to see it. It's kind of like deceiving.
2. Detect the deadlock and recover.
3. Carefully allocate resources dynamically to avoid deadlocks.
4. Prevent deadlocks by breaking the deadlock by one of the four necessary conditions.
Understanding the causes of deadlocks, especially the four necessary conditions that generate deadlocks, can be avoided, prevented, and
Unlock the deadlock. Therefore, in the system design, process scheduling and other aspects of how to not let these four necessary conditions to set up, how to accurately
The rational allocation of resources to avoid the process of permanent occupation of system resources. Also, prevent the process from being in a waiting state
Resource usage. Therefore, the allocation of resources should be given reasonable planning.
1. Condition One: Mutually exclusive condition
The condition is a negation, because the mutual exclusion of resources is determined by its own nature. However, virtual device technology can be used to eliminate the possibility of non-shared device deadlocks.
2. Condition Two: no deprivation condition
Difficult to achieve. The system generally allows the resource holders to voluntarily release resources, rather than adopt a preemptive approach.
3, condition Three: Occupy and wait
A static one-time resource allocation strategy can be used to ensure that deadlocks are not possible, which is a conservative method of static deadlock prevention, but resource utilization is low.
4. Condition Four: Loop condition
Check for loops before allocating resources, and predict if deadlocks can occur, as long as this is possible. That is, the method of dynamically allocating resources is adopted.
In summary, there are several strategies for resolving deadlocks:
1, using the static allocation method of resources to prevent deadlocks.
2, the use of dynamic allocation of resources, effective control allocation method to avoid deadlocks.
3. When the deadlock occurs, detect the deadlock and try to fix it.
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/84/5E/wKioL1eOvaWwo--dAABicX37W2M658.png-wh_500x0-wm_3 -wmp_4-s_2183225731.png "title=" Qq20160720075216.png "alt=" Wkiol1eovawwo--daabicx37w2m658.png-wh_50 "/>
This article from the "Learning Record" blog, reproduced please contact the author!
Cause && condition of deadlock && how to avoid deadlock