Algorithms Used in Banking Algorithms

To avoid deadlock in a system, Banker’s Algorithm includes the below two algorithms:

  • Resource Request Algorithm
  • Safety Algorithm

Safety Algorithm

The safety algorithm as the name suggests is used to determine and calculate the safety of the system. It checks on the state and sequence of the system to analyze system safety.

To determine the safety of the system it is important to understand: Work, Finish[i], and Need[i] w.r.t the available resources.

Here, Finish[i], and Need[i] include arrays of length n.

Step 1: Set Work as Available.

Work = available  - (1)
Finish[i] = false - (2)

Step 2: Check the availability of resources and continue the loop till Finish[i] is valued as false.

Need[i] <= Work - (3)
Finish[i] == false - (4)
Work = Work +Allocation(i) - (5)

Step 3: When Finish[i] is valued as true we can consider the system to be safe.

Finish[i] == true  - (6)

Resource Request Algorithm

The resource request algorithm as the name suggests is used to determine and calculate the system behavior when process makes request to resources.

To determine the resource request of the system it is important to understand: Allocation[i], Resource[i], Process[i] w.r.t the resources.

Let’s create a resource request array R[i] for each process P[i]. If the Resource Requesti [j] is equal to ‘K’, which means the process P[i] requires ‘k’ instances of Resources type R[j] in the system.

Step 1: Continue and go to step 2 if the condition is met else wait till the need meets the request.

Request(i) <= Need - (1)

Step 2: Continue and go to step 3 if the condition is met else wait till the resources become available.

Request(i) <= Available  - (2)

Step 3: Here, the requested resource is made available to the system process

Available = Available - Request - (3)
Allocation(i) = Allocation(i) + Request (i) - (4)
Need (i) = Need(i) - Request(i) - (5)

These two algorithms as discussed in the blog together constituted Banker’s algorithm.

Distributed System – Banker’s Algorithm

Distributed systems have a banker’s algorithm which serves as a deadlock avoidance algorithm. Bankers algorithm depicts the resource allocation strategy which can help in determining the availability of resources in the present or future and how these availability of resources will lead a Bankers’ system to go into deadlock. Different data structures can be used to implement the banker’s algorithm.

Similar Reads

Banking Algorithm Terminologies

1. Available:...

Algorithms Used in Banking Algorithms

To avoid deadlock in a system, Banker’s Algorithm includes the below two algorithms:...

Conclusion

Banker’s algorithm plays a very important part role in ensuring customer safety. It ensures resource requirements are fulfilled keeping in mind all the necessary deadlock conditions. Multi-process environments using a banker’s algorithm grant safety, and security and ensure adequate resources to process are made available....

FAQ on Banker’s Algorithm in a Distributed System

Q.1: Name the two algorithms that are important in banking algorithm...