Syntax
#include <stdlib.h> /* also in <process.h> */ void _endthread(void);Description
Note: If you use DosCreateThread, you must explicitly call _endthread to terminate the thread.
There is no return value.
In this example, the main program creates two threads, bonjour and au_revoir. The thread bonjour is forcibly terminated by a call to _endthread, while the au_revoir thread ends itself with an implicit call to _endthread.
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
void 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");
}
void au_revoir(void *arg)
{
int i = 0;
while (i++ < 5) /* This thread makes an implicit */
printf("Au revoir!\n"); /* call to _endthread */
}
int main(void)
{
unsigned long tid1;
unsigned long tid2;
tid1 = _beginthread(bonjour, NULL, 8192, NULL);
tid2 = _beginthread(au_revoir, NULL, 8192, NULL);
if (-1 == tid1 || -1 == tid2) {
printf("Unable to start threads.\n");
return EXIT_FAILURE;
}
DosWaitThread(&tid2, DCWW_WAIT); /* wait until threads 1 and 2 */
DosWaitThread(&tid1, DCWW_WAIT); /* have been completed */
return 0;
/****************************************************************************
The output should be similar to:
Au revoir!
Au revoir!
Au revoir!
Au revoir!
Au revoir!
Bonjour!
Bonjour!
Bonjour!
Bonjour!
Bonjour!
****************************************************************************/
}
Related Information