Lecture 7 Deadlocks
Lecture 7 Deadlocks
Lecture 7 Deadlocks
Learning Objectives
By the end of this session, you should be
able to
You can't get a job without experience; you can't get experience
without a job. Deadlock
The cause of deadlocks:
Each process needing what another process has. This results from
sharing resources such as memory, devices, links
The four conditions for deadlock
Avoidance
Any ordering of the process that can guarantee the completion of
all the processes is called safe sequence.
A system is said to be unsafe if no safe sequence exists for that
state.
Deadlock avoidance algorithm basically perform resource allocation
is such a manner that ensures the system will always remain in safe
state.
Strategies to deal with deadlock
Prevention
This approach is based on the idea of designing the system in such
a way that deadlocks become impossible.
Mutual exclusion, hold-and-wait, no pre-emption and circular-wait
are the four necessary conditions for a deadlock to occur.
If one of these conditions can never be satisfied then deadlock can
be prevented
Strategies to deal with deadlock
Prevention
i.Collective requests
These methods deny the hold and wait condition by ensuring that
whenever a process requests a resource it does not hold any other
resource.
ii.Ordered Requests
In this method circular-wait is denied such that each resource type
is assigned a unique global number to impose total ordering of all
resource types.
iii.Preemption
A preemptable resource is one whose state can be easily saved and
restored later. Deadlocks can be prevented using resource
allocation policies to deny no-preemption condition
Strategies to deal with deadlock
Deadlock Detection
If deadlocks are not avoided, then another approach is to detect
when they have occurred and recover somehow.
When should the deadlock detection be done? Frequently, or
infrequently?
The answer may depend on how frequently deadlocks are expected
to occur, as well as the possible consequences of not catching them
immediately. ( If deadlocks are not removed immediately when they
occur, then more and more processes can "back up" behind the
deadlock, making the eventual task of unblocking the system more
difficult and possibly damaging to more processes. )
Strategies to deal with deadlock