Four Conditions for deadlock and a deadlock Handling Policy

Source: Internet
Author: User

What is a deadlock? If every process in a process set is waiting for an event that can only be triggered by another process in the Set (including itself), this situation is a deadlock.

This definition may be a bit confusing. One of the simplest examples is resource A and resource B, which are both uneconomical resources. Now process C has applied for resource, process D also applies for resource B. The next operation of Process C requires resource B, and process D also applies for resource A, which causes a deadlock. This must have been viewed by everyone. Apply back to the definition: if every process (Process C and process D) in a process set (Process C and process D) all are waiting for only one other process in this set (for Process C, he is waiting for process D; for process D, he is waiting for Process C) events that can be triggered (resources are released ).

Resources here include soft resources (code blocks) and hard resources (such as scanners ). There are two types of resources: preemptable and nonpreemptable ). Generally, the deadlock caused by Resource deprivation can be solved by the re-allocation of resources by the system. Generally, the deadlock is caused by the unavailability of resources.

Four Conditions for deadlock

Mutual Exclusion: resources cannot be shared and can only be used by one process.
Hold and wait: processes that have obtained resources can apply for new resources again.
No pre-emption: allocated resources cannot be forcibly deprived from the corresponding process.
Loop wait condition (circular wait): several processes in the system form a loop in which each process is waiting for resources occupied by adjacent processes.

Deadlock Handling Policy

1. ignore this issue. For example, the ostrich algorithm can be applied in rare cases of deadlocks. 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.
2. Check the deadlock and restore it.
3. Carefully allocate resources dynamically to avoid deadlocks.
4. Avoid deadlock by breaking one of the four conditions.

 

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.