### _endthread -- Terminate Current Thread

Format

>     #include <stdlib.h>  /* also in <process.h> */
>     void _endthread(void);

Language Level: Extension
_endthread ends a thread that you previously created with _beginthread. When the thread has finished, it automatically ends itself with an implicit call to _endthread. You can also call _endthread explicitly to end the thread before it has completed its function, for example, if some error condition occurs.

Notes:

1. When using the _beginthread and _endthread functions, you must specify the /Gm+ compiler option to use the multithread libraries.
2. If you use DosCreateThread on OS/2, or CreateThread on Windows, you must explicitly call _endthread to terminate the thread.

Return Value
There is no return value.

Example
In this example, the main program creates two threads, bonjour and au_revoir.

Note: You must compile this example with the /Gm+ option.

    #if (1 == __TOS_OS2__)
        #define  INCL_DOS                          /*  OS/2  */
        #include <os2.h>
    #else
        #include <windows.h>                       /*  Windows  */
    #endif

    #include <stdio.h>
    #include <stdlib.h>
    #include <process.h>

    void _Optlink bonjour(void *arg)
    {
       int i = 0;

       while (i++ < 5)
          printf("Bonjour!\n");
       _endthread();                        /* This thread ends itself explicitly */
       puts("thread should terminate before printing this");
    }

_beginthread -- Create New Thread
<stdlib.h>
<process.h>
/Gm compiler option