Upload
gwendolyn-robertson
View
222
Download
0
Embed Size (px)
DESCRIPTION
Algorithm Step 1: Work=Available Finish=False Step 2: Find an i such that Finish[i]=false and Need i
Citation preview
Deadlock Avoidance-Banker’s Algorithm
Darsana Babu K Palanisamy
Assistant Professor Assistant Professor
IT ,CIET IT ,CIET
Coimbatore,TamilNadu Coimbatore,TamilNadu
Bankers algorithms Definition
• The algorithm avoids deadlock by denying or postponing the request if it determines that accepting the request could put the system in an unsafe state (one where deadlock could occur).
• When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time
Algorithm• Step 1: Work=Available Finish=False• Step 2: Find an i such that
Finish[i]=false and Need i <=work if no such I ,go to step4• Step 3: work=work+allocation i finish[i]= True goto step 2• Step 4: If finish[i]=true for all i then the system is safe
Terms
• Available :The number of instances currently available for resource j
• Maximum:themaximum number of instances of resource j that process i can request at anyone time
• Allocation :process i currently holdsinstances of j• Need:process i may need additional instance of
resource
Problem Statement
• There are Five girls they have three different balls Green,Blue ,Red to play.There are 10 Green Balls,5 Blue balls and 7 Red balls .Each girl wants particular number of balls of each colour to play.Since the number of balls is less than the total number of the balls they needed,Once they acquire the ball they will leave the balls they played so that ball can be used by other girls.
• Question How the balls can be passed such that all girl can play
with their balls
• GREEN BLUE RED
5 Friends
LILLYTINTU MITHU
MEENUGITHU
AllocationGREEN BLUE RED
MAXIMUMGREEN BLUE RED
AVAILABLEGREEN BLUE RED
NEEDGREEN BLUE RED
Lilly doesn’t get because available is less than need
GREEN BLUE REDAVAILABLE
<GREEN BLUE RED
Tintu play because Ball available is greater than need
GREEN BLUE REDAVAILABLE
>GREEN BLUE RED
AllocationGREEN BLUE RED
Meenu doesn’t get because available is less than need
GREEN BLUE REDAVAILABLE
<GREEN BLUE RED
Mithu play because Ball available is greater than need
GREEN BLUE REDAVAILABLE
>GREEN BLUE RED
AllocationGREEN BLUE RED
Githu play because Ball available is greater than need
GREEN BLUE REDAVAILABLE
>GREEN BLUE RED
AllocationGREEN BLUE RED
Lilly play because Ball available is greater than need
GREEN BLUE REDAVAILABLE
< GREEN BLUE RED
AllocationGREEN BLUE RED
Meenu play because Ball available is greater than need
GREEN BLUE REDAVAILABLE
>GREEN BLUE RED
Safe sequence
• They play in the following sequence such that all girls gets the ball to play
TINTU MITHU GITHU LILLYMEENU
Problem
• Five processes p0,p1,p2,p3,p4 3 resource types A with 10 instances B with 5 instances and C with 7 instances
• Allocation MAX Available Need
A B C0 1 02 0 03 0 22 1 10 0 2
A B C7 5 33 2 29 0 22 2 24 3 3
A B C
3 3 2
A B C7 4 31 2 26 0 00 1 14 3 1
Solution
Work= Finish =False• P1 :Finish[1]=T;work=• p3:Finish[3]=T ;work=• p4:Finish[4]=T ;work=• p0:Finish[0]=T ;work=• p2:Finish[2]=T ;work=
3 3 2
5 3 2
7 4 3
7 4 5
7 5 5
10 5 7
• Safe sequence is <p1,p3,p4,p0,p2>
Learning outcome
• Students will be able to understand deadlock avoidance
• Students will be able to explain different algorithm with real time arrangement.
• Students will be able to remember it longer
• Thank You