| 1 | #include "seatac.H" |
| 2 | |
| 3 | #ifdef __alpha |
| 4 | |
| 5 | // Define this to kill the process with a vengance instead of |
| 6 | // gracefully exiting. exit() tries to free memory, and is thus gets |
| 7 | // caught in the deadlock -- but is useful for debugging. |
| 8 | // |
| 9 | #define KILL_INSTEAD_OF_EXIT |
| 10 | |
| 11 | #ifdef KILL_INSTEAD_OF_EXIT |
| 12 | #include <signal.h> |
| 13 | #endif |
| 14 | |
| 15 | uint32 deadlockTested = 0; |
| 16 | uint32 deadlockPassed = 0; |
| 17 | |
| 18 | void* |
| 19 | deadlockDetector(void *) { |
| 20 | |
| 21 | fprintf(stderr, "Hello! I'm a deadlockDetector!\n"); |
| 22 | |
| 23 | detectAgain: |
| 24 | |
| 25 | // Wait for the deadlock checker to reset things |
| 26 | // |
| 27 | while ((deadlockTested == 1) || (deadlockPassed == 1)) |
| 28 | sleep(4); |
| 29 | |
| 30 | deadlockTested = 1; |
| 31 | char *x = new char [16]; |
| 32 | delete [] x; |
| 33 | deadlockPassed = 1; |
| 34 | |
| 35 | goto detectAgain; |
| 36 | |
| 37 | return(0L); // Ignore the warning! |
| 38 | } |
| 39 | |
| 40 | void* |
| 41 | deadlockChecker(void *) { |
| 42 | |
| 43 | fprintf(stderr, "Hello! I'm a deadlockChecker!\n"); |
| 44 | |
| 45 | checkAgain: |
| 46 | |
| 47 | // Wait for the tester to test |
| 48 | // |
| 49 | while (deadlockTested == 0) |
| 50 | sleep(5); |
| 51 | |
| 52 | // Give it another ten seconds to return |
| 53 | // |
| 54 | sleep(5); |
| 55 | |
| 56 | if (deadlockPassed == 0) { |
| 57 | fprintf(stderr, "\n\n\nESTmapper/search-- Deadlock detected! Aborting the process!\n\n"); |
| 58 | fflush(stderr); |
| 59 | #ifdef KILL_INSTEAD_OF_EXIT |
| 60 | kill(getpid(), SIGKILL); |
| 61 | #endif |
| 62 | exit(1); |
| 63 | } |
| 64 | |
| 65 | //fprintf(stderr, "Deadlock OK\n"); |
| 66 | |
| 67 | // Reset the testing/checking flags |
| 68 | // |
| 69 | deadlockPassed = 0; |
| 70 | deadlockTested = 0; |
| 71 | |
| 72 | goto checkAgain; |
| 73 | |
| 74 | return(0L); // Ignore the warning! |
| 75 | } |
| 76 | |
| 77 | #endif |