Constants:
______________________________________________
• Introduction to Bakery Algorithm
• Data structures for Banker’s Algorithm
• Safety Algorithm for Banker’s Algorithm
• Resource-Request Algorithm
• Working Example
Introduction to Banker’s Algorithm
• Multiple Instances
• System has no limited resources
• Advance claim for max resource allocation
• When a process gets all its resources it must return
them in a finite amount of time
Data Structures for Banker’s Algorithm
___________________________________________________
Let n = number of processes and m= number of resources types.
Available: Vector of length m. If available [j] =k , there are k instances of resources type available.
Max: n * m matrix. If Max [i,j] =k, then process may request at most k instances of resources type .
Allocation : n*m matrix. If allocation[i,j] =k then is currently allocated k instances of .
Need: n*m Matrix. If Need[i,j] =k then may need k more instances of .
to complete its task.
Need[i,j] =Max[i,j] – Allocation [i,j]
Finish: Boolean value, either true or false, if finish[i] = true for all I return safe else unsafe.
Safety Algorithm
__________________________________________
1.Let Available and Finish be vectors of length m and n,
respectively. Intialize Finish [i] = false for i=0,1,2,3,n-1
2.Find an I such that both
(a) Finish [i] =false (b) < Available
If no such I exists, go to sleep
Safety Algorithm
___________________________________________________
3. Available = Available +
finish[i] = true
Goto step 2
4.If Finsih [i] == true for all i , then system is in a safe
state.
Resource-Request Algorithm
___________________________________________________
• = request vector for process . If then process wants k
instances of resource type .
1.If = go to step 2.otherwise rasie error condition, since
process has exceeded its maximum claim
2.if < Available, go to step 3. Otherwise must wait,
since resources are not available
Resource-Request Algorithm
_________________________________________
3.Pretend to allocate requested resources to by modifying the state as
follows:
Available = Available -
= +;
=
If safe resources are allocated to
If unsafe must wait, and the old resource allocation state is restored.
Working Example of Banker’s Algorithm
_________________________________________
• Considering a system with five processes P0 through P4 and three
resources of type A, B, C. Resource type A has 10 instances, B has 5
instances and type C has 7 instances. Suppose at time t0 following
snapshot of the system has been taken.
Working Example of Banker’s Algorithm
_____________________________________
Solution: