/* deadlock function test driver */ int deadlock( int numres, // number of resource classes int numproc, // number of processes int *avltab, // pointer to the available table int *reqtab, // pointer to the requested table int *alloctab, // pointer to the allocated table int *numdead, // number of processes involved in deadlock int *deadtab); // id's of deadlocked processes #include #include int avltab[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int alloctab[8][8] = { {1, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 1} }; int reqtab[8][8] = { {0, 1, 0, 0, 0, 0, 0, 0}, // 0 {0, 0, 1, 0, 0, 0, 0, 0}, // 1 {0, 0, 0, 1, 0, 0, 0, 0}, // 2 {0, 0, 0, 0, 1, 0, 0, 0}, // 3 {0, 0, 0, 0, 0, 1, 0, 0}, // 4 {0, 0, 0, 0, 0, 0, 1, 0}, // 5 {0, 0, 0, 0, 0, 0, 0, 1}, // 6 {1, 0, 0, 0, 0, 0, 0, 0} // 7 /* 0 1 2 3 4 5 6 7 */ }; int deadtab[8]; int numdead; main() { int rc; int i; rc = deadlock(8, 8, avltab, reqtab[0], alloctab[0], &numdead, deadtab); printf("rc = %d \n", rc); printf("Deadlocked "); for (i = 0; i < numdead; i++) printf("%3d ", deadtab[i]); printf("\n\n"); reqtab[7][0] = 0; rc = deadlock(8, 8, avltab, reqtab[0], alloctab[0], &numdead, deadtab); printf("rc = %d \n", rc); printf("Deadlocked "); for (i = 0; i < numdead; i++) printf("%3d ", deadtab[i]); printf("\n\n"); }