|
|
1.1 root 1: /* 1.1.1.2 ! root 2: * Example of DosExitList usage. 1.1 root 3: * 4: * Typically, exit list routines are used to free any resources that the 5: * process may have owned, and leave any shared resources in a consistent 6: * state. Semaphores and shared memory are the common cases. It is not 7: * necessary to close files, since the system does that automatically 8: * when a process terminates. 9: * 10: * When a process is in exit list processing, it is already in a 11: * half-terminated state, and should be very careful not to cause 12: * problems or execute too long. Specifically, actions such as waiting 13: * on semaphores or for other processes to finish are extremely bad 14: * ideas. It is not possible to create new threads or exec another 15: * process while in exit list processing. 16: * 17: * This example shows exit list processing routines being added and removed. 18: * 1.1.1.2 ! root 19: * Created by Microsoft Corp. 1986, 1987, 1988 1.1 root 20: */ 21: 1.1.1.2 ! root 22: #define INCL_DOSPROCESS ! 23: ! 24: #include <os2def.h> ! 25: #include <bsedos.h> 1.1 root 26: 27: void e_handler1(); /* two exit handler routines */ 28: void e_handler2(); 29: 30: void main() 31: { 32: /* add a routine to the termination list */ 1.1.1.2 ! root 33: DosExitList(EXLST_ADD, e_handler1); 1.1 root 34: 35: /* add another routine to the termination list */ 1.1.1.2 ! root 36: DosExitList(EXLST_ADD, e_handler2); 1.1 root 37: 38: /* remove a routine from the termination list */ 1.1.1.2 ! root 39: DosExitList(EXLST_REMOVE, e_handler1); 1.1 root 40: 41: /* exit this process */ 42: printf("about to exit\n"); 1.1.1.2 ! root 43: DosExit(EXIT_PROCESS,0); 1.1 root 44: } 45: 46: /* first exit handler, not actually called in this example */ 47: void e_handler1() 48: { 49: /* shared resource cleanup should be done here */ 50: printf("this is exit handler 1\n"); 51: 52: /* advance to next handler in exit list (if any) */ 1.1.1.2 ! root 53: DosExitList(EXLST_EXIT, 0); 1.1 root 54: } 55: 56: /* second exit handler - this one is called when the process terminates */ 57: void e_handler2() 58: { 59: /* shared resource cleanup should be done here */ 60: printf("this is exit handler 2\n"); 61: 62: /* advance to next handler in exit list (if any) */ 1.1.1.2 ! root 63: DosExitList(EXLST_EXIT, 0); 1.1 root 64: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.