Deadlock "Deadlock reason," "a necessary condition for deadlock," "detect, prevent, prevention strategies deadlock" --- banker's algorithm

First, what is a deadlock?
The textbook definition:
"permanent" blocking deadlock between competing defined as a set of resources or inter-process communication process.
When each process a group process are waiting for an event (resources), while other processes only this group process can trigger the event. Because there is no event can be triggered, so deadlock is permanent.
Popular will is this:
two or more processes, have other processes necessary in order to continue execution of system resources, but each process before getting the resources they need will not release any resources they have used. These processes leading to blind waiting for the other to release resources, the emergence of the phenomenon of permanent obstruction.

Second, the reason for the deadlock?
(1) due to lack of system resources.
Order (2) to promote the process of running inappropriate.
(3) misallocation of resources and so on.

If the system resources are sufficient resources to process the request can be met, the possibility of a deadlock appears very low, otherwise
will be due to competition for limited resources and deadlock. Secondly, the process runs to promote order and at different speeds, it may produce a deadlock.

Third, the necessary conditions for Deadlock What?
1. mutually exclusive conditions : process requires resources allocated exclusive control is performed, i.e. a resource within a period of time occupied by only one process.
2. possession and wait : When the process is blocked due to request resources, continue to occupy the allocated resources.
3. Do not deprive condition : Resources process has been obtained before is not used, can not be denied, can only be released by themselves when you are finished.
4. Wait cycles : the presence of a closed process chain, each process constituting at least one resource required for the chain to the next process.

Fourth, prevention, avoidance, deadlock detection method
[1] deadlock prevention
resource time allocation: a one-time allocation of all resources, so you do not have :( request the destruction of possession and wait for conditions)
as long as there is a resource Debu to the distribution or allocation of resources to the process other damage :( possession wait condition)
can be deprived of resources: that is, when a process gained some resources, but not other resources, the release of resources has been occupied (destruction of the inalienable conditions )
resource allocation method ordered: each type of system resource to a given number, each sequence number is incremented by a process request resource, releasing the opposite (destruction loop waiting condition)
strategy yielded as follows:
1. the sequence obtained lock
2. timeout give up : this method can be a long wait for a lock according to fixed, so the thread can acquire the lock timeout after the initiative to release all locks previously obtained.

[2] Deadlock Avoidance
Deadlock Avoidance Deadlock prevention and compared, can allow more concurrency.
In the deadlock avoidance, whether to allow the current allocation of resources by determining whether the request may cause a deadlock determined. Therefore, to avoid deadlock situations we need to know the future course of the resource request.
Deadlock avoidance method:
1. The process starts refuse : If starting a process will lead to a deadlock, as the process does not start.
2. Resource allocation refuse : if a process request additional resources will lead to a deadlock, this resource allocation is not allowed.
Resource allocation denial, also known as the banker's algorithm.
Banker's algorithm: to ensure that the system of processes and resources are always in a safe state. When a process requests a set of resources, assuming that grants the request, thus changing the state of the system, and then determine whether the results in a safe state, if it agrees to the request; if not, block the process until the agreed system status after the request is still safe of.
Security Status: refers to at least one resource allocation sequence will not cause a deadlock (that is, all processes will run to the end).
Non-security state is contrary to this.
[3] deadlock detection
operating system periodically executes a detection algorithm to "waiting loop" exists. The algorithm can not guarantee to prevent deadlock, it can only determine whether there is currently a deadlock.
For details of the algorithm will not be described here: you can go to view the operating system and the essence of Chapter VI ----- chapter concurrent design principles to be understood.
The purpose is to restore the deadlock deadlock detection: as follows:
1. Cancel all deadlock processes (the most common).
2.Each roll back the process to some previously defined checkpoint, and restart all processes, which requires building a rollback mechanism and restart the system . The risk of this approach is: the original deadlock may occur again. The method relies on the uncertainty of concurrent processes.
3. Continuous cancel the process deadlock until there are no deadlocks . After each call to cancel the need to re deadlock detection algorithm to test whether there is a deadlock. Selected to cancel the order process should be based on a least-cost principle.
4. Continuous seize the resources until there are no deadlocks . As the third point, the need to use the selection method based on the cost, and the need to call the deadlock detection algorithm after each grab. The process is preempted resources must be rolled back to the state before obtaining the resource.

Principles have been selected to seize the resources of the process and the cancellation process mentioned above using one of the following:

  • So far the least time consuming processor.
  • So far at least produce an output
  • The remaining longest expected
  • So far the least amount of resources allocated Minimum
  • Lowest priority
Published 70 original articles · won praise 12 · views 9759

Guess you like

Origin blog.csdn.net/lovehang99/article/details/104627147
Recommended