Deadlock AvoidanceBankers Algorithm Darsana Babu Assistant Professor IT

Deadlock Avoidance-Banker’s Algorithm Darsana Babu Assistant Professor IT , CIET Coimbatore, Tamil. Nadu K Palanisamy Assistant Professor IT , CIET Coimbatore, Tamil. Nadu

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 step 4 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 LILLY TINTU MEENU MITHU GITHU

Allocation GREEN BLUE RED

MAXIMUM GREEN BLUE RED

AVAILABLE GREEN BLUE RED

NEED GREEN BLUE RED

Lilly doesn’t get because available is less than need AVAILABLE GREEN BLUE RED < GREEN BLUE RED

Tintu play because Ball available is greater than need AVAILABLE GREEN BLUE RED > GREEN BLUE RED

Allocation GREEN BLUE RED

Meenu doesn’t get because available is less than need AVAILABLE GREEN BLUE RED < GREEN BLUE RED

Mithu play because Ball available is greater than need AVAILABLE GREEN BLUE RED > GREEN BLUE RED

Allocation GREEN BLUE RED

Githu play because Ball available is greater than need AVAILABLE GREEN BLUE > BLUE RED

Allocation GREEN BLUE RED

Lilly play because Ball available is greater than need AVAILABLE GREEN BLUE < BLUE GREEN RED

Allocation GREEN BLUE RED

Meenu play because Ball available is greater than need AVAILABLE GREEN BLUE RED > GREEN BLUE RED

Safe sequence • They play in the following sequence such that all girls gets the ball to play TINTU MITHU GITHU LILLY MEENU

Problem • Five processes p 0, p 1, p 2, p 3, p 4 3 resource types A with 10 instances B with 5 instances and C with 7 instances • Allocation MAX Available Need A B C 0 1 0 7 5 3 2 0 0 3 2 2 3 0 2 9 0 2 1 1 2 0 0 2 4 A A B C 7 4 3 1 2 2 2 6 0 0 2 2 0 1 1 3 3 4 3 1 3 B 3 C 2
![Solution 3 2 Work= 3 Finish =False • P 1 : Finish[1]=T; work=5 3 Solution 3 2 Work= 3 Finish =False • P 1 : Finish[1]=T; work=5 3](http://slidetodoc.com/presentation_image_h2/7b080b2f9ebc71ca4f8a677ea19eadf6/image-25.jpg)
Solution 3 2 Work= 3 Finish =False • P 1 : Finish[1]=T; work=5 3 • p 3: Finish[3]=T ; work= 7 • p 4: Finish[4]=T ; work= 7 • p 0: Finish[0]=T ; work= 7 • p 2: Finish[2]=T ; work= 10 2 4 3 4 5 5 7

• Safe sequence is <p 1, p 3, p 4, p 0, p 2>

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
- Slides: 28