What it decides
The Banker's algorithm avoids deadlock. Before giving resources to a process, the system checks that it could still let every process finish, in some order, even if each one asked for everything it might need (its Max). If it can, the state is safe.
The safety check
- Need = Max − Allocation, for every process and every resource.
- Work = Available. Find a process whose Need ≤ Work in every resource. Let it finish: Work = Work + its Allocation. Repeat.
- If every process finishes, the state is safe, and the order they finished in is a safe sequence. If some never can, it's unsafe.
A request
- If Request > Need, it's an error: the process asked for more than it declared.
- If Request > Available, the process waits.
- Otherwise, pretend to grant it (Available − Request, Allocation + Request, Need − Request) and run the safety check. Safe: grant it. Unsafe: the process waits, and nothing changes.
The rules this calculator follows
- The check looks at P0, P1, … in order and goes round again until no one else can finish, as most worked answers do. Other safe sequences can exist; any valid one is right unless your question asks for a particular order.
- If your question gives the total of each resource instead of Available: Available = Total − the sum of that resource's column in Allocation.
Exam traps
- Unsafe doesn't mean deadlocked. It means a deadlock could happen.
- Need ≤ Work has to hold for every resource type, not for the total.
- A request can be refused even when enough is free: when granting it would leave an unsafe state.
More simulators: CPU scheduling, page replacement and disk scheduling.