OS Chapter 3 Deadlock
OS Chapter 3 Deadlock
Contents
2
Ω Resource
Ω Introduction to deadlocks
Ω The Ostrich algorithm
Ω Deadlock detection and recovery
Ω Deadlock avoidance
Ω Deadlock prevention
Ω Other issues
Resources
3
Formal definition :
A set of processes is deadlocked if each process in the set is
waiting for an event that only another process in the set can cause.
Usually the event is release of a currently held resource.
None of the processes can:-
run
release resources
be awakened
No progress
Four Conditions for Deadlock
7
correctness
Detection with One Resource of
14
Each Type
Consider a system with seven processes, A though G, and six
resources, R through W.
… Cont’d
15
a) Resource Trajectories
It is based on the concept of safe state
E= Existing resource ,
P= possessed resource ,
A =Available resource ,
Problems
may not know required resources at start of run
also ties up resources other processes could be using
Variation:
process must give up all resources
then request all immediately needed
3. Attacking the No Preemption Condition
31
Phase One
process tries to lock all records it needs, one at a time.
some record is needed that is already locked, the process just
releases all its locks and starts the first phase all over.
(no real work done in phase one)
If phase one succeeds, it starts second phase,
performing updates
releasing locks
Note similarity to requesting all resources at once, However, this
strategy is not applicable in general.
Algorithm works where programmer can arrange things
program can be stopped at phase 1, restarted.
Communication Deadlock
Another kind of deadlock can occur in communication systems (e.g.,
networks), in which two or more processes communicate by sending
messages.
A common arrangement is that process A sends a request message to
process B, and then blocks until B sends back a reply message.
Communication deadlocks cannot be prevented by ordering the
resources (since there are not) or avoided by careful scheduling (since
there are no moments when a request could be postponed).
The technique to break communication deadlocks is timeouts.
whenever a message is sent to which a reply is expected a timer is also started.
If the timer goes off before the reply arrives:-
the sender of the message assumes that the message has been lost
and
sends it again (and again and again if needed).
Livelock
In some situations, polling (busy waiting) is used to enter a critical
region or access a resource.
Let pair of processes (process A and process B)using two
resources.
To be polite, they give up the lock they are currently holding and
try again.
If the processes wait for required resource by spooling rather
than blocking, this situation is called livelock.
Thus we do not have a deadlock (because no process is blocked)
but we have something functionally equivalent to deadlock; will
make no further progress.
Starvation
37
Solution:
First-come, first-serve policy
Any Question?
38