Talk:Banker's algorithm: Difference between revisions

→‎Code in Java: new section
(EWD-123)
(→‎Code in Java: new section)
 
Line 12:
== More reading material ==
WP mentions EWD-108 and EWD-623, but I just saw that EWD-123 describes the Banker's Algorithm as well. -- [[User:Sonia|Sonia]] ([[User talk:Sonia|talk]]) 03:49, 31 October 2017 (UTC)
 
== Code in Java ==
 
Here's a link from where you can refer the code for Banker's algorithm in java
[https://github.com/rajat81/SPOS/blob/master/Bankers/src/com/rajatswnt/Bankers.java]
 
 
== Algorithm ==
 
Safety Algorithm
<br>
1) Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n
 
2) Find an i such that both
a) Finish[i] = false
b) Needi <= Work
if no such i exists goto step (4)
 
3) Work = Work + Allocation[i]
Finish[i] = true
goto step (2)
 
 
 
 
4) if Finish [i] = true for all i
then the system is in a safe state