|
|
1.1 root 1: /*
2: * Example of DOSEXITLIST usage.
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: *
19: * Copyright (C) Microsoft Corp. 1986
20: */
21:
22: #include <doscalls.h>
23:
24: void e_handler1(); /* two exit handler routines */
25: void e_handler2();
26:
27: #define EXLIST_ADD 1 /* add routine to exit list */
28: #define EXLIST_REMOVE 2 /* remove routine from exit list */
29: #define EXLIST_DONE 3 /* terminate exit list handler */
30:
31: void main()
32: {
33: /* add a routine to the termination list */
34: DOSEXITLIST(EXLIST_ADD, e_handler1);
35:
36: /* add another routine to the termination list */
37: DOSEXITLIST(EXLIST_ADD, e_handler2);
38:
39: /* remove a routine from the termination list */
40: DOSEXITLIST(EXLIST_REMOVE, e_handler1);
41:
42: /* exit this process */
43: printf("about to exit\n");
44: DOSEXIT(1,0);
45: }
46:
47: /* first exit handler, not actually called in this example */
48: void e_handler1()
49: {
50: /* shared resource cleanup should be done here */
51: printf("this is exit handler 1\n");
52:
53: /* advance to next handler in exit list (if any) */
54: DOSEXITLIST(EXLIST_DONE, (char *)0);
55: }
56:
57: /* second exit handler - this one is called when the process terminates */
58: void e_handler2()
59: {
60: /* shared resource cleanup should be done here */
61: printf("this is exit handler 2\n");
62:
63: /* advance to next handler in exit list (if any) */
64: DOSEXITLIST(EXLIST_DONE, (char *)0);
65: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.