end a thread of execution
#include <process.h> void _endthread(void);
The _endthread() function is used to terminate a thread created by _beginthread(). For each operating environment on which _endthread() is supported, the _endthread() function uses the appropriate system call to end the current thread of execution.
#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <process.h> #define STACK_SIZE 4096 #if defined(__386__) #define FAR #else #define FAR __far #endif volatile thread_count = 0; void FAR child( void FAR *parm ) { char * FAR *argv = (char * FAR *) parm; int i; for( i = 0; argv[i]; i++ ) { printf( "argv[%d] = %s\n", i, argv[i] ); } thread_count--; _endthread(); } void main() { char *stack; char *args[3]; int tid; int status; args[0] = "child"; args[1] = "parm"; args[2] = NULL; stack = (char *) _nmalloc( STACK_SIZE ); thread_count++; tid = _beginthread( child, stack, STACK_SIZE, args ); while( thread_count ); }
WATCOM