Deadlock Avoidance Methods
- Also, Deadlock can be avoided if certain information about processes is available to the operating system before allocation of resources, such as
- Which resources a process will consume in its lifetime.
- Simplest and most useful model requires that each process declare the maximum number of resources of each type that a process may need.
- The Deadlock Avoidance Methods algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition.
- Resource-allocation state defined by the number of available and allocated resources, and the maximum demands of the processes.
- For every resource request, the system sees whether granting the request will mean that the system will enter an unsafe state, meaning a state that could result in deadlock.
- The system then only grants requests that will lead to the safe state.
- In order for the system to be able to determine whether the next state will be safe or unsafe.
- It must know in advance at any time:
- resources currently available
- Moreover, resources currently allocated to each process
- resources that will require and released by these processes in the future
- It is possible for a process to be in an unsafe state but for this not to result in a deadlock.
The notion of safe/unsafe states only refers to the ability of the system to enter a deadlock state or not.
- Example for Deadlock Avoidance Methods, if a process requests A which would result in an unsafe state, but releases B which would prevent circular wait, then the state is unsafe but the system is not in deadlock.
- One known algorithm that used for deadlock avoidance the Banker’s algorithm, which requires resource usage limit to be known in advance. However, for many systems, it is impossible to know in advance what every process will request. This means that deadlock avoidance is often impossible.
- Two other algorithms are Wait/Die and Wound/Wait, each of which uses a symmetry breaking technique.
- In both these algorithms, there exists an older process (O) and a younger process (Y). Process age can determine by a timestamp at process creation time. Smaller timestamps are older processes, while larger timestamps represent younger processes.