2. HOME PREVIOUS TOPIC
NEXT
PREVIOUS QUESTION PAPERS
FOR OS
CPP TUTORIALS
2
3. Recap
In the last class, you have learnt:
• Deadlock Avoidance
• Safe State and Safe sequence
• Banker’s Algorithm
• Data Structures needed for implementing Banker’s
Algorithm
3
5. Deadlock Detection
• Deadlock may occur if a system does not employ
– Deadlock prevention
– Deadlock avoidance
• In this environment the system must provide
– An algorithm that examines the state of the system to
determine whether a deadlock has occurred
– An algorithm to recover from the deadlock
5
6. Deadlock Detection
The Deadlock detection algorithms in the previous slide
are explained with the following conditions
• Single Instance of Each Resource Type
• Several Instances of Resource Type
6
7. Single Instance of each Resource Type
• If all resources have only a single instance, then
we can define a Deadlock detection algorithm i.e.,
– A variant of resource allocation graph
– This graph is known as wait-for graph
• A deadlock exists in the system if and only if the
wait-for graph contains a cycle
7
10. Several Instances of a Resource type
• The wait-for graph scheme is not applicable to a
resource-allocation system with multiple instances of
each resource
• The Deadlock-detection algorithm contains several
time-varying data structures. Namely
– Available
– Allocation
– Request
10
11. Several Instances of a Resource Type
• Available: A vector of length m indicates the
number of available resources of each type
• Allocation: An nxm matrix defines the number of
resources of each type currently allocated
• Request: An nxm matrix indicates the current
request of each process
11
12. Detection-Algorithm Usage
• When should we invoke the detection algorithm?
The answer depends on
– How often is a deadlock likely to occur?
– How many process will be affected by deadlock when it
happens?
12
13. Detection-Algorithm Usage
• Deadlocks occur only when some process makes a
request that cannot be granted immediately
• If the deadlock occurs frequently,
– The detection algorithm should be invoked frequently or
– Invoked for every resource request
• The above methods incur overhead in computation time
• So an alternative method is
– To invoke the algorithm at less frequent intervals for Ex. Once
per hour
13
14. Summary
In this class, you have learnt
• Deadlock detection under different condition
namely
• Systems with single instance of each resource type
• Several instance of a resource type
14