AOS Lecture 5
AOS Lecture 5
Under the normal mode of operation, a process may utilize a resource in only the
following sequence:
1. Request: If the request cannot be granted immediately, then the requesting
process must wait until it can acquire the resource.
2. Use: The process can operate on the resource.
3. Release: The process releases the resource.
Necessary Conditions for Deadlock
Coffman (1971) identified four conditions that must hold simultaneously for
there to be a deadlock.
1. Mutual Exclusion Condition: The resources involved are non-shareable.
Explanation: At least one resource must be held in a non-shareable mode,
that is, only one process at a time claims exclusive control of the resource. If
another process requests that resource, the requesting
process must be delayed until the resource has been released.
2. Hold and Wait Condition: Requesting process hold already the resources
while waiting for requested resources.
Explanation: There must exist a process that is holding a resource already
allocated to it while waiting for additional resource that are currently being
held by other processes.
Necessary Conditions for
Deadlock
3 No-Preemptive Condition: Resources already allocated to a process
cannot be preempted.
Explanation: Resources cannot be removed from the processes are used to
completion or released
voluntarily by the process holding it.
4. Circular Wait Condition: The processes in the system form a circular list
or chain where each process
in the list is waiting for a resource held by the next process in the list. There
exists a set {P0, P1, …, P0} of
waiting processes such that P0 is waiting for a resource that is held by P1, P1 is
waiting for a resource that is
held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is
waiting for a resource that is held by P0.
DEADLOCK AVOIDANCE
This approach to the deadlock problem anticipates deadlock before it actually
occurs. This approach
employs an algorithm to access the possibility that deadlock could occur and
acting accordingly. If the necessary
conditions for a deadlock are in place, it is still possible to avoid deadlock by being
careful when resources are
allocated. It employs the most famous deadlock avoidance algorithm that is the
Banker’s algorithm.
A deadlock-avoidance algorithm dynamically examines the resource-allocation
state to ensure that a
circular wait condition can never exist. The resource-allocation state is defined by
the number of available and
allocated resources, and the maximum demands of the processes.
Safe and Unsafe States
A system is said to be in a Safe State, if there is a safe execution sequence. An
execution sequence is
an ordering for process execution such that each process runs until it terminates
or blocked and all request for
resources are immediately granted if the resource is available.
A system is said to be in an Unsafe State, if there is no safe execution
sequence. An unsafe state may
not be deadlocked, but there is at least one sequence of requests from processes
that would make the system
deadlocked.
Diagram