dos12.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DosExit (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSPROCESS
 
VOID DosExit(fTerminate, usExitCode)
USHORT fTerminate;    /* terminate current/all threads  */
USHORT usExitCode;    /* result code for parent process */
 
The DosExit function ends a thread or a process and all its threads.
 
The DosExit function is a family API function.
 
Parameter   Description
────────────────────────────────────────────────────────────────────────────
 
fTerminate  Specifies whether to terminate the current thread or the process
            and all its threads. If this parameter is EXIT_THREAD, only the
            current thread ends. If it is EXIT_PROCESS, all threads in the
            process end.
 
usExitCode  Specifies the program's exit code.
 
Return Value
 
This function does not return a value.
 
Comments
 
If the fTerminate parameter is EXIT_THREAD, the function ends the current
thread. If the current thread is the last one in the process, the process
also ends. If the fTerminate parameter is EXIT_PROCESS, the DosExit function
terminates all threads in the process and creates a final temporary thread.
The temporary thread executes any functions given in the list created by the
DosExitList function. When this last thread ends, the system frees any
resources used by the process. The exit code specified by the last call to
the DosExit function is supplied to the parent process by using the
DosCwait function.
 
If thread one calls DosExit, the fTerminate parameter is ignored, and the
process is terminated as if the fTerminate parameter was set to
EXIT_PROCESS.
 
Restrictions
 
In real mode, the following restriction applies to the DosExit function:
 
♦  The function always exits from the current program, since there are no
   threads in the real-mode environment.
 
Example
 
This example creates a thread, referred to as thread 2. This example shows
two ways of stopping thread 2: by stopping all threads in the process and by
stopping thread 2 specifically. Thread 1, the main process, exits and ends
all threads by calling the DosExit function with the first parameter set to
EXIT_PROCESS. Thread 2, the thread created with the call to DosCreateThread,
ends only itself, by calling DosExit with the first parameter set to
EXIT_THREAD.
 
BYTE bStackArea[2048];
 
main() {
    .
    .
    .
    PVOID pStack2 = bStackArea + 512;
    TID tidThread2;
    DosCreateThread(Thread2, &tidThread2, pStack2);
    .
    .
    .
    DosExit(EXIT_PROCESS,      /* exit process                   */
        0);                    /* return value                   */
}
VOID FAR Thread2() {
    .
    .
    .
    DosExit(EXIT_THREAD,       /* exit thread, process continues */
        0);                    /* return value                   */
}
 
See Also
 
DosCwait, DosExecPgm, DosExitList