Deadlock and Process communication

Source: Internet
Author: User
Tags mutex

One, deadlock

1. Deadlock Concept

As a result of competing resources or communication relationships, two or more threads are executing in an event that waits for each other only to be raised by other processes.

2. Resources

There are many types of resources, including CPU execution time, memory space, I/O devices, etc. are called resources. Each of these types of resources has multiple instances. The process accesses resources in three steps: Request/Fetch, use/Occupy, release.

Resources are divided into two categories: reusable resources such as hardware processors, I/O channels, primary and secondary memory, devices, and data structures such as files, databases, semaphores, etc. in the software. Another class is consuming resources, such as interrupts in I/O buffers, signals, messages, and so on.

3. Resource allocation diagram

Processes and resources are represented by vertices (processes are circles, resources are rectangles) in the diagram, and processes and resources are represented by a forward edge. The process requests the resource to point to the resource, and the resource is used by the process to point to the process.

Example:

4. Requirements for deadlocks

Mutex: Only one process can use one resource instance at any time.

Hold and wait: The process keeps at least one resource and is waiting for resources that other processes hold.

Non-preemption: Resources can only be released voluntarily after the process is used.

Cyclic wait: There is a collection of waiting processes, each waiting for a resource to be occupied by another process, forming a ring.

5. Deadlock Handling method

1) Deadlock Prevention

Prevention is the adoption of a strategy to limit the concurrent process requests for resources, so that the system does not meet the requirements of deadlocks at any time. A method of deadlock prevention for each of the necessary conditions:

Mutex: Encapsulates a mutually exclusive shared resource to be accessible at the same time.

Hold and wait: When a process requests a resource, it requires that it not hold any other resources. Only allow the process to request all required resources at the beginning of execution. This method has a low resource utilization.

Non-preemption: Frees an already-owned resource if the process requests a resource that cannot be allocated immediately. The allocation operation is performed only when all required resources are available at the same time.

Cyclic wait: Sorts the resources, requiring the process to request the resources sequentially.

2) Deadlock avoidance

Banker algorithm:

See whether the remaining number of resources can meet one or more processes, can be satisfied with the allocation of one of the processes, and then after the process is finished, the resources previously occupied and the resources just allocated to the operating system (banker), the operating system continues to find the next current resources to meet its running process, The algorithm ends until all processes have finished executing, or if a running process is not currently found.

Example:

First T2, the rest of the order is free, is a safe state.

is not a security state.

3) Deadlock detection and recovery

Allows the system to enter a deadlock state, the system periodically calls the deadlock detection algorithm to search for a deadlock in the system's resource allocation diagram, and when a deadlock occurs, it is resumed with a deadlock recovery mechanism.

The deadlock detection algorithm is similar to the banker's algorithm, except that there is no maximum request volume in the deadlock detection.

Example:

First T0 or T2, then T2 or T0, the rest of the casual. Security status.

Non-secure state.

Deadlock and Process communication

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.