Deadlock of operating system

Source: Internet
Author: User

Deadlock (DeadLock)


The concept of deadlock

The so-called deadlock refers to two or two processes in the execution process, because of the contention for resources caused by a mutual waiting phenomenon, if there is no external force, they will not be able to advance, this time said the system is in a deadlock state or the system has produced a deadlock, these are always waiting for each other process called the deadlock process.

For example, if thread a locks record 1 and waits for record 2, and thread B locks record 2 and waits for record 1, a deadlock occurs for two threads.

Causes of deadlocks

1. Due to insufficient system resources.
2. The sequence in which the process is running is inappropriate.
3. Improper allocation of resources.

 If the system has sufficient resources, the resource requests of the process can be met, the likelihood of deadlocks is very low, otherwise it will be locked into a deadlock because of the contention for limited resources. Second, the process is run in a different order and speed, and may also produce a deadlock.

The necessary conditions for deadlock generation

1. Mutex conditions: A resource can only be used by one process at a time.
2.
request and hold:when a process is blocked by requesting a resource, it remains in place for the resources that have been obtained.
3.
Inalienable (non-preemption):The resources that the process has acquired cannot be forcibly stripped until the end of use is exhausted.
4.
Loop Wait:a cyclic waiting resource relationship is formed between several processes.
 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.

How to handle deadlocks

Prevent deadlocks

In advance, one of the four necessary conditions for the destruction of a deadlock occurs.

    • Discard the "request and hold" condition: The process is a one-time application resource.

      Discard "Request": When the process comes, allocate all resources once (if the system is satisfied), so there will be no more "requests".

      Discard "hold": As long as one resource is not allocated, no other resources are allocated to the process.

    • Abandon the "no deprivation" condition: In this approach, the process is a request for resources. If a process obtains some resources but does not have access to other resources, it frees up the resources it occupies.

    • Discard the "loop wait" condition: sort the resources and apply the order as the process requests the resources.

Avoid deadlocks

Prevention beforehand is not the four necessary condition to destroy the deadlock, but a method to prevent the system from entering the unsafe state, which is commonly used in the more perfect system. Banker algorithm

Security state: means that the system can follow a sequence of processes (P1,P2,... PN), to allocate the required resources for each process pi until each process is satisfied with the maximum resource requirements for each process, so that each can be successfully completed. If the system cannot find such a security sequence, the system is said to be in an unsafe state.

Deadlock detection

Do not take any restrictive measures in advance, and do not have to check whether the system has entered the unsafe zone, this method allows a deadlock, the key is that a deadlock occurs, the system can detect the deadlock through the detection mechanism, and accurately determine the deadlock-related processes and resources, and then take appropriate measures, from the system will have occurred in the deadlock clean

Unlock deadlock

This is used with the detection deadlock kit. When the system detects that a deadlock has occurred, the process is freed from the deadlock state. A common approach is to undo or suspend some of the processes in order to reclaim some resources, and then assign those resources to a process that is already in a blocked state and turn it into a ready state to continue running.


This article is from the "11408774" blog, please be sure to keep this source http://11418774.blog.51cto.com/11408774/1831924

Deadlock of operating system

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.