Deadlocks 2
Deadlocks 2
• If there is deadlock occurs in the system, then the OS will just ignore the deadlock and
reboot the system in order to function well.
• Using the ostrich algorithm is one of the methods of dealing with deadlocks.
• This will not be a good idea to solve the deadlock problem, hence the drawbacks are
more, without finding solutions to deadlock problems.
• The methods for handling deadlocks
• Deadlock detection,
• Deadlock recovery,
• Deadlock avoidance,
• Deadlock prevention.
Deadlock Avoidance
Resource allocation graph for deadlock avoidance An unsafe state in a resource allocation graph
Banker's Algorithm
• Consider a system with five processes P0 through P4 and three resource types A, B,
and C.
• Resource type A has ten instances, resource type B has five instances, and resource
type C has seven instances
• Suppose that, at time T0, the following snapshot of the system has been taken:
• A B C
• 10 5 7
• Work = Available and Finish[i] = false
• for i = 0, 1, ..., n - 1.
• P0: 1. work = available
• Work = 3 3 2
• 2. Need <= work
• 7 4 3 <= 3 3 2 (false)
• P1: work = available
• Work = 3 3 2
• 2. Need <= work1
• 2 2 <= 3 3 2 (true)
• 3. work = work + allocation
• = 332 + 200=532
• P2: 1. work = available
• Work = 5 3 2
• 2. Need <= work
• 600 <= 5 3 2 (false)
• P3: work = available
• Work = 5 3 2
• 2. Need <= work
• 011 <= 53 2 (true)
• 3. work = work + allocation
•=532+211=743
• P4: work = available
• Work = 7 4 3
• 2. Need <= work
• 4 3 1 <= 7 4 3 (true)
• 3. work = work + allocation
• =743 + 002=745
• P0: work = available
•Work = 745
• 2. Need <= work
• 743 <= 745 (true)
• 3. work = work + allocation
•=745+010=755
• P2: work = available
• Work=755
• 2. Need <= work
• 600 <= 745 (true)
• 3. work = work + allocation
• = 755+302=10 5 7
Banker's Algorithm – Example
• Result - if the process execution is in following order, then the system will be
safe.