Deadlock causes and solutions

Source: Internet
Author: User

Deadlock ConditionMutual Exclusion: resources cannot be shared and can only be used by one process. Hold and wait: the process has obtained some resources, but the obtained resources are not retained because the requests to other resources are blocked. No pre-emption: Some system resources cannot be preemptible. When a process has obtained such resources, the system cannot forcibly reclaim them. It can only be released after the process is used up.. Circular wait: several processes form a ring chain, each occupying the next resource requested by the other party..Deadlock Handling Policy

1. ignore this issue. For exampleOstrich Algorithm.

2. Check the deadlock and restore it. 3. Carefully allocate resources to avoid deadlocks. 4. prevent deadlock by breaking one of the four conditions.

Ostrich algorithm:

This algorithm can be applied in rare cases where deadlocks occur. Why is it called the ostrich algorithm? Because it is said that an ostrich will bury its head under the ground when it sees danger. Maybe the ostrich will feel no danger if it does not. It is a bit like a hacker.

Banker algorithm:

The so-called bankers algorithm is to first check whether the system will be deadlocked after the resources are allocated.If deadlocks occur, they are not allocated. Otherwise, they are allocated.

According to the banker's algorithm, when a process requests resources, the system allocates system resources according to the following principles:

(1) A process can be accepted when the maximum resource demand of a process does not exceed the number of resources in the system.

(2) A process can request resources in stages. When the total number of requests cannot exceed the maximum demand.

(3) When the existing resources of the system cannot meet the number of resources required by the process, requests to the process can be postponed, but the process can always obtain resources within a limited period of time.

(4) When the existing resources of the system can meet the number of resources required by the process, you must test whether the existing resources of the system can meet the maximum number of resources required by the process, if yes, the resource will be allocated based on the current application volume; otherwise, the allocation will be postponed.

Deadlock Resolution Policy

The policies for deadlock are as follows:

(1) deadlock prevention: damage to any of the conditions necessary to cause a deadlock can prevent the deadlock. For example, if a user is required to apply for all resources at a time when applying for resources, this damages the conditions for persistence and waiting. After the resource is layered and the previous layer of resources is obtained, can apply for the next layer of resources, which breaks the loop wait condition. Prevention usually reduces system efficiency.

(2) deadlock avoidance: The process determines whether these operations are safe each time it requests resources. For example, the banker algorithm is used. Deadlocks prevent Algorithm Execution from increasing system overhead.

(3) Deadlock Detection: both prevention and avoidance of deadlocks are ex ante measures. The Deadlock Detection determines whether the system is in a deadlock state. If yes, the deadlock removal policy is executed.

(4) deadlock removal: This is used in combination with Deadlock Detection. The method used is deprivation. Forcibly reclaim the resources owned by a process and allocate them to other processes.

 

Deadlock Avoidance:The prevention of deadlocks is to prevent the occurrence of deadlocks by breaking the conditions for creation, but this method damages the system's concurrency and concurrency. The first three conditions of a deadlock are necessary conditions for the deadlock to be generated. That is to say, the conditions that must be met for the deadlock to be generated, instead of the three conditions, the deadlock must be generated, so long as the fourth condition is avoided logically, the deadlock can be avoided. To avoid deadlocks, the first three conditions are allowed, but a reasonable resource allocation algorithm is used to ensure that the closed process chain of loop wait will never be formed to avoid deadlocks. This method supports parallel execution of multiple processes. To avoid deadlocks, the system dynamically determines whether to allocate a resource to the requested process. The method is as follows: 1. if the resource requested by a process causes a deadlock, the system rejects the process. 2. if a resource is allocated, the system rejects the next deadlock. To avoid the deadlock, you must know the number of resources and their attributes in advance.

Deadlock causes and solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.