Avoidance

The system must have a priori information available. Such as the maximum nuymber of resources a process may need.

The algorithm then dynamically examines the state of resource allocation to ensure that a circular wait condition may never occur. The state of resource allocation is defined as the number of available and allocated resources, and the maximum demands of each running process.

When a process requests a resource, the system must decide if immediately allocating this resource leaves it in a safe state, i.e. there exists a sequence of all the processes in the system such that for each $P_i$, the resources that $P_i$ can still request is satisfied by the currently available resources $+$ the resources held by all the $P_j$ with $j<i$.

If $P_i$'s needs are not immediately available, it will wait until all $P_j$ are finished. When $P_j$ is finished, $P_i$ obtains it's needed resources, completes and releases the allocated resources, and terminates. When $P_i$ terminates, $P_{i+1}$ can then obtain its needed resources, and so on.

If the system is in a safe state, there is no deadlocks, an unsafe state suggests implies there is the possibility of a deadlock. Avoidance ensures that the system will never enter an unsafe state. If each resource has a single instance, this may be done using a resource allocation graph.O Otherwise, one may use Banker's algorithm.