start a new thread of execution
#include <process.h> int _beginthread( register void (*start_address)(void *), void *stack_bottom, unsigned stack_size, void *arglist );
The _beginthread() function is used to start a new thread of execution at the function identified by start_address with a single parameter given by arglist.
For each operating environment under which _beginthread() is supported, the _beginthread() function uses the appropriate system call to begin a new thread of execution.
The new thread uses the memory identified by stack_bottom and stack_size for its stack.
The thread ends when it exits from its main function or calls exit(), _exit() or _endthread().
The variable/function _threadid, which is defined in stddef.h, may be used by the executing thread to obtain its thread ID. It's a far pointer to an int.
Under QNX, the number of threads an application can create is limited by the number of processes.
the thread ID for the new thread, if successful, or -1 on an error, indicating that the thread couldn't be started. The global variable errno is set to indicate the type of error that occurred.
#include <stdio.h> #include <stdlib.h> #include <process.h> #include <stddef.h> #define STACK_SIZE 4096 #if defined(__386__) #define FAR #else #define FAR __far #endif void FAR child( void FAR *parm ) { char * FAR *argv = (char * FAR *) parm; int i; printf( "My thread ID = %d\n", *_threadid ); for( i = 0; argv[i]; i++ ) { printf( "argv[%d] = %s\n", i, argv[i] ); } _endthread(); } void main() { char *stack; char *args[3]; int tid; args[0] = "child"; args[1] = "parm"; args[2] = NULL; stack = (char *) malloc( STACK_SIZE ); tid = _beginthread( child, stack, STACK_SIZE, args ); }
WATCOM