DJ3-5 Deadlock overview

Table of contents

3.5 Deadlock overview

3.5.2 Deadlocks in Computer Systems

1. Competing resources

2. Improper sequence of processes

3.5.3 Necessary conditions and handling methods of deadlock

1. Necessary conditions for deadlock

2. Methods to deal with deadlock

3.6 Deadlock prevention

3.6.1 Removing the "request and hold" condition

3.6.2 Removal of the "no deprivation" condition

3.6.3 Abandoning the "loop wait" condition

3.8 Deadlock detection and release

3.8.1 Deadlock detection

1. Resource Allocation Map

2. Deadlock theory

3. Data structure in deadlock detection

3.8.2 Deadlock Removal


3.5 Deadlock overview

3.5.2 Deadlocks in Computer Systems

Definition of Deadlock

Each process in a group of processes waits for an event that can only be raised by other processes in the group.

1. Competing resources

2. Improper sequence of processes

3.5.3 Necessary conditions and handling methods of deadlock

1. Necessary conditions for deadlock

If a deadlock occurs, the above four conditions must be met, but meeting the above four conditions does not necessarily result in a deadlock.

  • It can be seen that the way to prevent deadlock is: don't meet the above four conditions at the same time!

1) Mutually exclusive conditions

It is stipulated that within a period of time, a resource can only be occupied by one process, and other processes requesting the resource must wait until the process that occupies the resource is used up and released.

2) Request and hold conditions

The process has already occupied at least one resource, and it proposes a new resource application, and the resource is already occupied by other processes. At this time, the requesting process is blocked, but it still holds on to the resources it has already occupied.

3) No deprivation of conditions

The resources already occupied by the process cannot be deprived before they are used up, and can only be released by the process itself when it is used up.

4) Loop wait condition

When a deadlock occurs, the following circular chain must exist: P0 in the process set { P0, P1, P2, ... , Pn } is waiting for a resource owned by P1, P1 is waiting for a resource owned by P2, ..., Pn is waiting for a resource owned by P0.

2. Methods to deal with deadlock

From (1) to (4), the degree of deadlock prevention is gradually weakened, but correspondingly, the resource utilization rate is increased, and the frequency of process blocking due to resource factors is reduced, that is, the degree of concurrency is increased.

3.6 Deadlock prevention

Ways to prevent deadlock: Make one of the 2nd, 3rd, and 4th conditions out of the four necessary conditions untenable, so as to avoid deadlock.

As for the necessary condition 1, because it is determined by the inherent properties of the equipment, not only cannot be changed, but should also be guaranteed.

3.6.1 Removing the "request and hold" condition

The system stipulates that all processes must apply for all the resources they need during the entire running process at one time before starting to run. In this way, the process will no longer make resource requests during the entire running period.

Avoiding the phenomenon of occupying the latrine and not shitting

  • Advantages: simple, easy and safe.
  • Disadvantages: (1) Resources are seriously wasted. (2) Make the process often starve.

But there is still the phenomenon of occupying the latrine and not shitting

3.6.2 Removal of the "no deprivation" condition

Processes make requests for resources one by one, rather than all requests at once.

When a process that has already held some resources proposes a new resource request that cannot be satisfied, it must release all the resources it has held, and re-apply when it is needed later.

This means that the resources already occupied by the process will be temporarily released, or deprived!

This method has many disadvantages:

  • (1) It is complicated to implement; the cost is high: the previous work fails, or the work before and after is not continuous
  • (2) Repeated applications and releases delay turnaround time, increase system overhead, and reduce system throughput

3.6.3 Abandoning the "loop wait" condition

The method specifies:

  1. Linearly sort all resources in the system by type and give them different serial numbers
  2. Each process must request resources in strict order of increasing sequence number

In this way, no loops can appear in the resulting resource allocation graph.

Pros: Improved resource utilization and system throughput.

Disadvantages: (1) The serial number must be relatively stable, thus limiting the addition of new devices

(2) The order in which resources are used by the job is different from the order stipulated by the system, requiring continuous release and application

(3) The method of applying for resources in order limits the user's simple and autonomous programming

3.8 Deadlock detection and release

3.8.1 Deadlock detection

When the system allocates resources for a process, if no restrictive measures are taken, the system must provide means to detect and resolve deadlocks.

1. Resource Allocation Map

Use a circle to represent a process, and a box to represent a class of resources. Since there may be multiple resources of one type, a point in the box represents one resource of one type of resource. In addition, the request edge is the process pointing to the point in the box, and the allocation edge is the point in the box pointing to the process.

2. Deadlock theory

The sufficient condition for S to be a deadlock state is: if and only if the resource allocation graph of S state is not completely reducible. This sufficient condition is called the deadlock theory.

3. Data structure in deadlock detection

3.8.2 Deadlock Removal

When a process deadlock is found, two methods are often used to remove the deadlock:

1) Deprivation of resources. Deprive a sufficient number of resources from other processes to the deadlocked process to resolve the deadlocked state.

2) Undo the process. The easiest way to undo the process is to make all the deadlock processes die; or to undo the processes one by one in a certain order until enough resources are available to eliminate the deadlock state.

Supongo que te gusta

Origin blog.csdn.net/m0_64140451/article/details/130074669
Recomendado
Clasificación