The concept deadlock

1. Knowledge Overview

What is a deadlock
process deadlock, starvation, death cycle of the difference between
a necessary condition for Deadlock
when it will deadlock
processing policy deadlock

2. What is a deadlock

Here Insert Picture Description
Here Insert Picture DescriptionIn a concurrent environment, the phenomenon of the processes due to competition for resources caused by waiting for a resource in the hands of each other, leading to the process are blocked, they can not move forward, is a "deadlock
after the deadlock if no external force to interfere, the process will not move forward

3. The difference between deadlock, starvation, death cycle

Deadlock: the processes wait for each resource in the hands of each other, leading to the process are blocked and can not advance forward phenomenon.

Hunger: lack of resources due to the long wanted, a process can not advance forward phenomenon. For example: In the short process priority (SPF) algorithm, if the arrival of a steady stream of short process, it has been a long process to get the processor, which occurred a long process "hunger."

Infinite loop: a process execution has been impossible to escape the phenomenon of a loop. Sometimes because the program logic bug caused programmers sometimes deliberately designed.

Here Insert Picture Description

4. Deadlock conditions necessary

Deadlock must meet the following four conditions, as long as any of the conditions is not satisfied, the deadlock will not occur.
Mutually exclusive conditions : only competition for resources will have exclusive use of the results in a deadlock (as the philosopher of chopsticks, printer device). Like memory, the speaker would allow multiple processes simultaneously using resources that do not lead to deadlock (because the process do not block waiting for such resources).
Not deprivation : Resources obtained before the process is not used, not by the
force took other processes, can only take the initiative to release.
Request and keeping conditions : the process has been maintained for at least one resource, but proposed a new resource request, the resource has been occupied by another process, this time requesting process is blocked, but on their existing resources to keep hold.
Loop wait condition : there is a waiting loop process resource chain, the chain of resources acquired each process simultaneously processes the next request.

Note! There must wait cycle when a deadlock occurs, but not necessarily a deadlock occurs waiting loop

If the same number of resources is greater than 1, even if there is to wait for the cycle, it may not be a deadlock occurs. But if the system is only one of each type of resource, it is necessary and sufficient condition loop waiting for the deadlock.

5. What happens when a deadlock

1. The competition for system resources. The processes of competition for resources (such as printers) inalienable could lead to deadlock, competition for resources can be deprived (CPU) is not cause deadlock.
2. The order process to move illegal. Request and order the release of resources properly, will also lead to a deadlock. For example, concurrent execution of processes P1, P2 are applied for and took possession of the resources R1, R2, P1 and immediately after the process of application resource R2, and the process P2 and apply resources R1, both because of resource application is blocked to share each other, thus deadlock.
3. improper use of semaphores can also cause deadlock. As producer - consumer issues, if the P operation to achieve mutual exclusion prior to implementation P synchronous operation, it may lead to a deadlock. (Mutex can be, viewed as a synchronization signal amount is an abstract system resources)

In short, can not be deprived of misallocation of resources, it could lead to a deadlock.

6. deadlock processing strategy

1. Prevention deadlock. Destruction of one or several four requirements in Deadlock.
2. To avoid deadlocks. Unsecure prevent the system, to avoid deadlock (Banker algorithm) by some means
3. The deadlock detection and release. Allowing the deadlock occurred, but the operating system is responsible for detecting a deadlock, then take some measures to relieve the deadlock.

7. Summary

Here Insert Picture Description

Published 168 original articles · won praise 1 · views 2974

Guess you like

Origin blog.csdn.net/yrx420909/article/details/104440985