|
|
Microsoft OS/2 SDK 03-01-1988
/*
* Example of DosExitList usage.
*
* Typically, exit list routines are used to free any resources that the
* process may have owned, and leave any shared resources in a consistent
* state. Semaphores and shared memory are the common cases. It is not
* necessary to close files, since the system does that automatically
* when a process terminates.
*
* When a process is in exit list processing, it is already in a
* half-terminated state, and should be very careful not to cause
* problems or execute too long. Specifically, actions such as waiting
* on semaphores or for other processes to finish are extremely bad
* ideas. It is not possible to create new threads or exec another
* process while in exit list processing.
*
* This example shows exit list processing routines being added and removed.
*
* Created by Microsoft Corp. 1986, 1987, 1988
*/
#define INCL_DOSPROCESS
#include <os2def.h>
#include <bsedos.h>
void e_handler1(); /* two exit handler routines */
void e_handler2();
void main()
{
/* add a routine to the termination list */
DosExitList(EXLST_ADD, e_handler1);
/* add another routine to the termination list */
DosExitList(EXLST_ADD, e_handler2);
/* remove a routine from the termination list */
DosExitList(EXLST_REMOVE, e_handler1);
/* exit this process */
printf("about to exit\n");
DosExit(EXIT_PROCESS,0);
}
/* first exit handler, not actually called in this example */
void e_handler1()
{
/* shared resource cleanup should be done here */
printf("this is exit handler 1\n");
/* advance to next handler in exit list (if any) */
DosExitList(EXLST_EXIT, 0);
}
/* second exit handler - this one is called when the process terminates */
void e_handler2()
{
/* shared resource cleanup should be done here */
printf("this is exit handler 2\n");
/* advance to next handler in exit list (if any) */
DosExitList(EXLST_EXIT, 0);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.