Deadlock: A deadlock that occurs when multiple processes are competing for shared resources, and without external forces, these processes will never be able to move forward.
Security state and unsafe state: The security state refers to the system being able to allocate its required resources to each process in a sequence of processes, up to the maximum requirements, so that each process can be completed successfully. If the system does not exist such a series, it is said that the system is in an unsafe state.
Cause of deadlock: 1, competitive system resources. 2, the process of promoting the wrong order.
The necessary conditions for creating a deadlock:
1. Mutually exclusive condition: The process requires exclusive control over the allocated resources, that is, for a period of time, a resource is occupied only by a process.
2. Request and hold condition: When a process is blocked by a request for resources, the resource that the other party obtains remains in place.
3. No deprivation: The process has obtained the resources before they are used, cannot be deprived, can only be released by themselves when the use is complete.
4, loop waiting conditions: In the event of a deadlock, there must be a process-the circular chain of resources.
The above four is the necessary condition for generating a deadlock, as long as a deadlock occurs, the above four pieces need to occur.
Basic methods for resolving deadlocks:
Prevent deadlocks:
1. One-time allocation of resources.
2. Conditions of deprivation: that is, when a new resource of a process is fulfilled, the resources already occupied are released (destruction of the inalienable conditions)
3. Orderly allocation of resources: the system assigns a number to each class of resources, and each process requests resources in ascending order of numbers, and releases the opposite (destroys the loop wait condition).
Avoid deadlocks:
Several strategies for preventing deadlocks can severely damage system performance. Therefore, when the deadlock is avoided, a weaker limit is applied to achieve satisfactory system performance. Because the process is allowed to dynamically request resources in a policy that avoids deadlocks. Thus, the system pre-calculates the security of the resource allocation before the resource allocation, if the allocation does not cause the system to enter an unsafe state, the resource is allocated to the process, otherwise, the process waits.
Deadlock Detection:
First, specify a unique number for each process and each resource;
The Resource Allocation table and the process waiting table are then established.
To resolve a deadlock:
When a process deadlock is found, it should be freed from the deadlock state immediately, often using the following methods:
1, deprivation of resources: from other processes to deprive a sufficient amount of resources to the deadlock process to resolve the deadlock state.
2, the revocation process: can directly revoke the deadlock process or the least expensive process, until there is sufficient resources available, the deadlock state is eliminated; the so-called price is the priority, the cost of operation, the importance and value of the process.
IOS: Dead Lock