/* James O' Connor 50703338 17/12/02 This is my original work Program to implement safety algorithm and bankers algorithm for process management / resource allocation. It's a bit if a rough hack, not very OO :) */ #include #define M 3 #define N 5 using namespace std; void readMax(int max[N][M]); void printMax(int max[N][M]); bool lessEqNeedWork(int index, int need[N][M], int work[M]); void printSafeStatus(int work[M], bool finish[N], int step); void printRequestStatus(int request[M], int available[M], int step); bool isSafe(int max[N][M], int allocation[N][M], int system[N], int need[N][M], int available[M]); int main(int argc, char **argv) { int i, j, k; int max[N][M]={ {7,5,3}, {3,2,2}, {9,0,2}, {2,2,2}, {4,3,3} }; int allocation[N][M]={ {0,1,0}, {2,0,0}, {3,0,2}, {2,1,1}, {0,0,2} }; int available[M]={3,3,2}; int need[N][M]={ {7,4,3}, {1,2,2}, {6,0,0}, {0,1,1}, {4,3,1} }; int system[N]={10, 5, 7}; int work[M]={0}; int request[N][M]={ {0, 2, 0}, {1, 0, 2}, {1, 0, 0},//request that can be granted immediatly {0, 2, 1},//request that can't be granted immediatly {3, 3, 0}, }; bool step3 = true; //initialise arrays bool safe = isSafe(max, allocation, system, need, available); for(i=0; i need[i][j]) { printRequestStatus(request[i], available, 1); //step 1 cout << "Error condition: request exceeded maximum claim!"< available[j]) { printRequestStatus(request[i], available, 2); //step 2 cout << "Request greater than available resources," << "process must wait"< work[i]) return false; return true; } /* */