Four necessary conditions for deadlocks and strategies for dealing with deadlocks

Source: Internet
Author: User

What is a deadlock?

If each process inside a process collection waits for an event that can only be raised by one of the other processes in the collection, including himself, this is a deadlock.

Resources A, B, Resource A and resource B are both inalienable resources,
Now that process C has applied for resource A, process D has also requested resource B,
process C will need resource b for the next operation, and process D happens to be requesting resource A,
process C, D is not getting the next resource, then it triggers a deadlock. The
then applies back to the definition: if each process (process C and Process D) of a process set inside (process C and Process D) is waiting for only one of the other processes in this collection (for process C, he is waiting for process D; For process D, he waits for process C) to raise the event (freeing the appropriate resource).

Resources here include soft resources (blocks of code) and hard resources (such as scanners). Resources can generally be divided into two types: the deprivation of resources (preemptable) and the Inalienable resources (nonpreemptable). In general, deadlocks caused by the deprivation of resources can be solved by the redistribution of resources in the system, so generally speaking, the deadlock is caused by the inalienable resources.

Four necessary conditions for a deadlock

Mutex condition (Mutual exclusion): A resource cannot be shared and can only be used by one process.
Request and hold condition (holds and wait): a process that has already received a resource can request a new resource again.
Non-deprivation condition (no pre-emption): The allocated resources cannot be forcibly stripped from the corresponding process.
Cyclic wait condition (Circular wait): Several processes in the system make up loops in which each process waits for resources that are being consumed by neighboring processes.

Policies to handle 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.

Four necessary conditions for deadlocks and strategies for dealing with deadlocks

Related Article

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.