Banker’s Algorithm Assignment Help
Manages a number of instances for resource kinds.
n = number of processes; m=number of resource types;
- Available vectore[1..m], available[j]-the number of instance now available with regard to resourcej.
- Max matrix[1..n, 1..m]. max[i,j]-the maximum number associated with instance associated with resource j that process i can request at any one time.
- Allocation materix[1..n,1..m]-process i currently holds allocation [i,j] instance associated with resource j.
- Need matrix[1..n, 1..m]- process i may need additional need [i,j] instance associated with resource j.
need[i,j] = max[i,j]- allocation[i,j]
Banker’s Algorithm - Safety Procedure
Local Data Structures:
- Work vector[1..m], initialize work to available
- Finish vector[1..n], initized to false for each process i.
1. find process i such that finish[i]=false and needi<=work
if i exists do
work = work + allocationi
go back to 1.
2. no such i exists
When finish[i]= true for all i in 1..n, then the system is in safe state. whoever, the processes whose index is false may potentially be involved in a deadlock in the future.
Banker’s Algorithm - Resource Request
Requesti-request vector- how much the number of additional instances for each resource type process i request at this time.
1. If not (requesti<=available) process i must wait- no sufficient resource at this time.
2. Tentatively allocate the requested resources to process i;
available = available - requesti
allocation = allocationi + requesti
needi = needi - requesti
3. Check safety of state. If safe the resource are allocated. if not safe then cancel the tentative allocation and process i must wait.