In attempting to learn about it, I found there were two types of explanations of the Banker's algorithm - confusing pseudocode (not great when you're asked to do it by hand), and ones which failed to give any semblance of a "why". Sometimes both at once. So I opened Krita, and now there's this, which hopefully serves as a better teaching tool. Enjoy!
I've also written a small tool which performs the Banker's algorithm, showing the steps along the way (jump to the tool!).
Some details have been left out or simplified to emphasise the purpose above. Please tell me if there's something heinously wrong, though.
Explanation
Visualisation Tool
Inputs
{{ resourceIdentifier(resource) }} | |
---|---|
P{{ process }} |
{{ resourceIdentifier(resource) }} | |
---|---|
P{{ process }} |
{{ resourceIdentifier(resource) }} |
---|
{{ resourceIdentifier(resource) }} | |
---|---|
P{{ process }} | {{ cell }} |
Result (scroll along!)
Error: process P{{ result.process }} has exceeded its declared maximum of resource {{ resourceIdentifier(result.resource + 1) }} Error: process P{{ result.process }} has declared a maximum of {{ result.maxWas }} instances of resource {{ resourceIdentifier(result.resource + 1) }}, however resource {{ resourceIdentifier(result.resource + 1) }} only has {{ result.resourceTotal }} instances total {{ error.message }}
{{ resourceIdentifier(resource) }} |
---|
{{ cell }} |
P{{ step.process }} can run:
P{{ step.process }} terminates and frees its allocated resources:
All processes can successfully acquire their maximum number of resources then terminate.
Therefore, the system is in a safe state.
No other process is able to acquire the resources it requires to terminate.
Therefore, the system is in an unsafe state which may lead to deadlock.