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 , the resources
that
can still request is satisfied by the currently available resources
the resources held by all the
with
.
If 's needs are not immediately available, it will wait until all
are finished. When
is finished,
obtains it's needed resources, completes and releases the allocated resources, and terminates.
When
terminates,
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.