Cause and necessary conditions of deadlock + basic solution to deadlock

Source: Internet
Author: User

 Deadlock:It refers to a deadlock caused by competition and sharing of resources by multiple processes. Without external force, these processes will never be able
Forward.

Security Status and unsafe status: the system can allocate the required resources to each process in a certain process order, so that each process can be completed smoothly. If the system does not have such a sequence, the system is declared insecure.

 

 

 

 

Cause of deadlock: (1)Competing System Resources(2)Improper process Promotion order

Conditions for deadlock:

Mutex conditions: processes require scheduling of allocated resources, that is, a resource is only occupied by a process within a period of time.

Request and retention conditions: when a process is blocked due to a resource request, it will not release the obtained resources.

Non-deprivation condition: resources obtained by a process cannot be deprived before they are used up. They can only be released by themselves when they are used up.

Loop wait condition: in the case of a deadlock, a process-a Ring Chain of resources is inevitable.

The basic method to solve the deadlock:

Deadlock Prevention:

One-time resource allocation:(Damage request and retention conditions)

Resource deprivation:That is, when new resources of a process fail to meet the requirements, the occupied resources are released (which damages the conditions that cannot be deprived)

Orderly resource allocation method:The system assigns a number to each type of resources, and each process requests Resources in the ascending order of numbers. The opposite is true when resources are released (the loop wait condition is broken)

 

Avoid deadlocks:

Several deadlock prevention policies can seriously damage system performance. Therefore, when avoiding deadlocks, we must apply weak restrictions to achieve satisfactory system performance. Because the process is allowed to dynamically apply for resources in a deadlock-free policy. Therefore, the system calculates the security of resource allocation in advance before allocating resources. If this allocation does not cause the system to enter an insecure state, the resource will be allocated to the process; otherwise, the process will wait. The most representative Deadlock Avoidance algorithm is the bankers algorithm.

 

Deadlock Detection

Specify a unique number for each process and resource;

Create a resource allocation table and a process wait table, for example:

 

 

 

 

Deadlock relief:

When a process deadlock is detected, it should be immediately freed from the deadlock state. The common methods are as follows:

Resource deprivation:Deprive other processes of sufficient resources to the deadlock process to cancel the deadlock;

Undo process:You can directly undo the deadlock process or undo the process with the lowest cost until there are enough resources available and the deadlock status is eliminated. The so-called price refers to priority, run price, process importance and value.

 

 

 

 

 

 

 

 

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.