To end the execution of the current thread, call DosExit, specifying the action code as 0. It is good practice to end each thread in the application individually.
If the thread that is ending is the last thread in the process, or if the request is to end all threads in the process, then the process also ends. All threads except one are ended, and that thread executes any routines in the list specified by DosExitList. When this is complete, the resources of the process are released, and the result code that was specified in the DosExit call is passed to any thread that calls DosWaitChild for this process.
In the following code fragment, the main routine starts another program, SIMPLE.EXE, and then expects a return code of 3 to be returned. SIMPLE.EXE sets the return code with DosExit.
#define INCL_DOSPROCESS /* Process and thread values */ #include <os2.h> #include <stdio.h> #define START_PROGRAM "SIMPLE.EXE" #define RETURN_OK 3 CHAR szLoadError[100]; PSZ pszArgs; PSZ pszEnvs; RESULTCODES rcReturnCodes; APIRET ulrc; ulrc = DosExecPgm(szLoadError, /* Object name buffer */ sizeof(szLoadError), /* Length of object name buffer */ EXEC_SYNC, /* Asynchronous/Trace flags */ pszArgs, /* Argument string */ pszEnvs, /* Environment string */ &rcReturnCodes, /* Termination codes */ START_PROGRAM); /* Program file name */ if (ReturnCodes.codeResult == RETURN_OK) /* Check result code */ printf("Things are ok..."); else printf("Something is wrong..."); /*----------------SIMPLE.EXE------------------*/ #define INCL_DOSPROCESS /* Process and thread values */ #include <os2.h> #include <stdio.h> #define RETURN_CODE 3 main() { printf("Hello!\n"); DosExit(EXIT_THREAD, /* End thread/process */ RETURN_CODE); /* Result code */ }
When you specify DosExit for thread 1 (the initial thread of execution started by OS/2 for this process), all of the threads in the process are ended, and the process is ended.