Syntax
#include <stdlib.h> /* also in <process.h> */
int _beginthread(void (*start_address) (void *),
(void *)stack,
unsigned stack_size,
void *arglist);
Description
start_address
An alternative to this function is the OS/2 DosCreateThread function. If you use DosCreateThread, you must also use a #pragma handler statement for the thread function to ensure proper C exception handling. You should also call the _fpreset function at the start of the thread to preset the 387 control status word correctly. Using DosCreateThread requires that you use _endthread to terminate the thread.
If successful, _beginthread returns the thread ID number of the new thread. It returns -1 to indicate an error.
This example uses _beginthread to start a new thread bonjour, which prints Bonjour! five times and then implicitly ends itself. The program then prints a statement indicating the thread identifier number for bonjour.
#define INCL_DOS#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
static int wait = 1;
void bonjour(void *arg)
{
int i = 0;
while (wait) /* wait until the thread id has been printed */
DosSleep(0l);
while (i++ < 5)
printf("Bonjour!\n");
}
int main(void)
{
int tid;
tid = _beginthread(bonjour, NULL, 8192, NULL);
if (-1 == tid) {
printf("Unable to start thread.\n");
return EXIT_FAILURE;
}
else {
printf("Thread started with thread identifier number %d.\n", tid);
wait = 0;
}
DosWaitThread((PTID)&tid, DCWW_WAIT); /* wait for thread bonjour to */
/* end before ending main thread */
return 0;
/****************************************************************************
The output should be similar to :
Thread started with thread identifier number 2.
Bonjour!
Bonjour!
Bonjour!
Bonjour!
Bonjour!
****************************************************************************/
}
Related Information