13 - Bankers Algorithm s Multiple instances. s Each process...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Banker’s Algorithm Multiple instances. Each process must a priori claim maximum use. When a process requests a resource it may have to wait. When a process gets all its resources it must return them in a finite amount of time.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data Structures for the Banker’s Algorithm Available: Vector of length m . If available [ j ] = k , there are k instances of resource type R j available. Max: n x m matrix. If Max [ i,j ] = k , then process P i may request at most k instances of resource type R j . Allocation: n x m matrix. If Allocation[ i,j ] = k then P i is currently allocated k instances of R j. Need: n x m matrix. If Need [ i,j ] = k , then P i may need k more instances of R j to complete its task. Need [ i,j] = Max [ i,j ] – Allocation [ i,j ]. Let n = number of processes, and m = number of resources types.
Background image of page 2
Safety Algorithm 1. Let Work and Finish be vectors of length m and n , respectively. Initialize: Work = Available Finish [ i ] = false for i - 1,3, …, n. 2. Find and i such that both: (a) Finish [ i ] = false (b) Need i Work If no such i exists, go to step 4. 3. Work = Work + Allocation i Finish [ i ] = true go to step 2. 4. If Finish [ i ] == true for all i , then the system is in a safe state.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Resource-Request Algorithm for Process P i Request = request vector for process P i . If Request i [ j ] = k then process P i wants k instances of resource type R j . 1. If Request i Need i go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim. 2. If Request i Available , go to step 3. Otherwise P i must wait, since resources are not available. 3. Pretend to allocate requested resources to P i by modifying the state as follows: Available = Available = Request i ; Allocation i = Allocation i + Request i ; Need i = Need i Request i;; If safe the resources are allocated to P i . If unsafe P i must wait, and the old resource- allocation state is restored
Background image of page 4
Example of Banker’s Algorithm 5 processes P 0 through P 4 ; 3 resource types A (10 instances), B (5instances, and C (7 instances). Snapshot at time T 0 : Allocation Max Available A B C A B C A B C P 0 0 1 0 7 5 3 3 3 2 P 1 2 0 0 3 2 2 P 2 3 0 2 9 0 2 P 3 2 1 1 2 2 2 P 4 0 0 2 4 3 3
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example (Cont.) The content of the matrix. Need is defined to be Max – Allocation. Need A B C P 0 7 4 3 P 1 1 2 2 P 2 6 0 0 P 3 0 1 1 P 4 4 3 1 The system is in a safe state since the sequence < P 1 , P 3 , P 4 , P 2 , P 0 > satisfies safety criteria.
Background image of page 6
P 1 Request (1,0,2) (Cont.) Check that Request Available (that is, (1,0,2) (3,3,2) true. Allocation Need Available A B C A B C A B C P 0 0 1 0 7 4 3 2 3 0 P 1 3 0 2 0 2 0 P 2 3 0 1 6 0 0 P 3 2 1 1 0 1 1 P 4 0 0 2 4 3 1 Executing safety algorithm shows that sequence < P 1 , P 3 , P 4 , P 0 , P 2 > satisfies safety requirement. Can request for (3,3,0) by
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 66

13 - Bankers Algorithm s Multiple instances. s Each process...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online