This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/_bthread.c

61 lines
1.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <malloc.h>
#include <process.h>
#include <dos.h>
#if defined(__386__)
#define FAR
#define STACK_SIZE 8192
#else
#define FAR __far
#define STACK_SIZE 4096
#endif
static volatile int WaitForThread;
void FAR child( void FAR *parm )
{
char * FAR *argv = (char * FAR *) parm;
int i;
printf( "Child thread ID = %x\n", *_threadid );
for( i = 0; argv[i]; i++ ) {
printf( "argv[%d] = %s\n", i, argv[i] );
}
WaitForThread = 0;
_endthread();
}
void main()
{
char *args[3];
#if defined(__NT__)
unsigned long tid;
#else
char *stack;
int tid;
#endif
args[0] = "child";
args[1] = "parm";
args[2] = NULL;
WaitForThread = 1;
#if defined(__NT__)
tid = _beginthread( child, STACK_SIZE, args );
printf( "Thread handle = %lx\n", tid );
#else
#if defined(__386__)
stack = (char *) malloc( STACK_SIZE );
#else
stack = (char *) _nmalloc( STACK_SIZE );
#endif
tid = _beginthread( child, stack, STACK_SIZE, args );
printf( "Thread ID = %x\n", tid );
#endif
while( WaitForThread ) {
sleep( 0 );
}
}