Banker’s Algorithm, which is a deadlock avoidance algorithm. It is called the Banker’s Algorithm, because it could be used by a bank to make sure that money is allocated in such a way that all customer needs are met. When a new process enters the system, it declares the maximum number of instances that are needed. This number cannot exceed the total number of resources in the system. If the process can be accommodated based upon the needs of the system, then resources are allocated, otherwise the process must wait. The algorithm is actually made up of two separate algorithms: the safety algorithm and the resource allocation algorithm.
This program is tested using Borland C++ Compiler.
File Name | Description |
---|---|
BANKER.CPP | main application |
CLASS.CPP | banker class declaration |
DEFINE.CPP | banker class definitions |
GRAPHICS.CPP | graphics related functions |
The following data structures are needed:
no_of_process
represents the number of processes and no_of_resource
represents the number of resource types.
-
Available
- A vector (array) of available resources of each type
- If
available[j] = k
, thenk
instances ofR
j are available.
-
Max
- A
n
no_of_process
byno_of_resource
matrix - Defines maximum demand for each process
maximum[i][j] = k
, then processP
i may request at mostk
instances of resourceR
j.
- A
-
Allocation
- A
n
no_of_process
byno_of_resource
matrix 2.Defines number of resources of each type currently allocated to each process allocation[i][j]=k
, then processP
i is currently allocatedk
instances ofR
j.
- A
-
Need
- A
n
no_of_process
byno_of_resource
matrix - Indicates remaining resource need of each process
- If
need[i][j] = k
, then processP
i needsk
more instances ofR
j. need[i][j] = maximum[i][j] - allocation[i][j]
- A
Main Application Window
Safe Sequence Check
Safe Sequence Result
Algorithm Inprogress
Current State
Input Validation
Memory Deallocation