 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
int
work[m] = available; // to
accumulate resources
|
|
|
boolean
finish[n] = {FALSE,…}; // non finished yet
|
|
|
do {
|
|
|
find an i such that (finish[i]==FALSE)
&& (need[i]<work)
|
|
|
// process i can complete all of its
requests
|
|
|
finish[i] = TRUE; // done with this process
|
|
|
work = work + allocation[i]; // assume
this process gave
|
|
|
// all
its allocation back
|
|
|
} until
(no such i exists);
|
|
|
|
|
|
if (all
finish entries are TRUE) {
|
|
|
// system is safe. i.e., we found a sequence a processes
|
|
// that will lead to everyone
finishing
|
|
|
}
|
|