Reasonable interpretation of four necessary conditions for a "deadlock"

I compiled a free Java Advanced information, covering Java, Redis, MongoDB, MySQL, Zookeeper, Spring Cloud, Dubbo distributed high concurrency and other tutorials, a total of 30G, needs its own collection.
Portal: https://mp.weixin.qq.com/s/JzddfH-7yNudmkjT0IRL8Q

 

"" Deadlock "reasonable interpretation of the four necessary conditions" is divided into three parts:

[1] "deadlock" means

[2] reasonable interpretation of "deadlock" reasons, and four necessary conditions

[3] "deadlock" of Prevention and Relief

1. "deadlock" means

The so-called deadlock: refers to two or more processes in the implementation process, due to the competition for resources or A blocking phenomenon caused due communicate with each other, without external force, they will not be able to promote it. At this time, say the system is in deadlock state or system to produce a deadlock, which is always in the process of waiting for another process called the deadlock.

2. Cause "deadlock" created and a reasonable interpretation of the four necessary conditions

It causes a deadlock can be attributed to the following two points:

(1) competition for resources. When the system resource is shared by multiple processes such as printers, and other public queues, their number is insufficient to meet the needs of the process, various processes may compete for the deadlock.

Room (2) order process to move illegal. Process during operation, request and order the release of resources properly, will also lead to deadlock the process.

 

Generates four necessary conditions for deadlock:

1. mutex (Mutual exclusion): there is a resource, it can only be assigned to a thread (also called threads) to use at some point;

2. hold (Hold and wait): When requested resource has been occupied leading to the implementation of thread blocked, without releasing resources occupants not only the resources, but also continue to request more resources;

3. Inalienable (No preemption): thread to obtain exclusive resources can not be forcibly deprived, in other words, only the occupants own resources in order to free up resources;

4. Wait ring (Circular wait): a plurality of thread acquiring exclusive resource in a different order, thereby forming an annular waiting situation, imagine executed by a plurality of threads composed of endless chains, each thread is waiting for the next thread release resources it holds.

 

Found so far, all content can be found in the textbook books, Baidu, forums, blog, it seems to be dogmatic list.

We found that seen many times, but often when needed (development, written test, interview) always want to look back - hard to get rid of the forgotten, the memory of the cycle - I think the reasons for this phenomenon is due to: stay in the mechanical memory.

Because the content of our textbooks, forums, blog is in all likelihood a list of these concepts - but with little further explanation to explain the necessity of its existence (four why not a necessary condition, why a lot?) And internal logic.

Perhaps the following explanation can make you encounter this problem, you can not turn textbooks, you can not access Baidu talking about -

<1>. "Deadlock" produce several necessary conditions?

"Deadlock" in the "dead" sound through "four" is the four conditions. (Though far-fetched, but for memorizing, you will find very useful!)

<2>. "Four" is a necessary condition for lock refers to what?

 

(After the process is assigned (holding) resources and waiting (application) other resources)> 2 hold and wait - 1. Resource mutually exclusive (property resource, will not belong to the same time / assigned to multiple processes). - > 3 inalienable (for allocated resources, no longer forced to withdraw) -> 4 annular wait (wait formed interdependent resources between processes, and do not polite)

Then use simple words to further explain the escalating situation. 1-> 2-> 3-> 4 gradually resource allocation condition is progressive, strengthen, the upgrade process: resources are mutually exclusive each belonging to one process (1 mutex);

Resource Allocation me occupied and I would also like to apply for other resources (2 hold and wait);

I can not take you occupied resources, you can not take me occupied resources (3. Inalienable);

I apply the resources you that, in my resources you apply this (4 cycle wait), culminating in a mutual possession, waiting for another standoff ~

3. "deadlock" of Prevention and Relief

Understand the cause of a deadlock, in particular, to produce four necessary conditions for deadlock, it were possible to avoid, prevent and relieve the deadlock, the elimination of any of the four necessary conditions for deadlock in the dead can prevent and relieve lock.

Easy to see, the four requirements deadlock, the second, third and four conditions are relatively easy to remove.

1, static allocation: the use of static resource allocation strategies (static resource allocation process refers to a process in establishing the allocation of all the resources it needs), destroy "part assigned" condition;

2, deprivation: deprivation allow the process to other processes using the resources occupied, thereby undermining the "inalienable right" conditions;

3, ordered allocation: the use of resources and orderly distribution method, destruction "loop" condition.

Guess you like

Origin www.cnblogs.com/yuxiang1/p/12083809.html