static void *print(void*);
int okend = EXIT_SUCCESS;
(void)thr_create(0,0, print, (void *)"hello, ", 0L,0);
(void)thr_create(0,0, print, (void *)"world.\n", 0L,0);
static void *print(void *s)
shows the traditional first program written when one enters
a new regime of the UNIX programming environment.
In this example,
we create one thread to output ``"hello, "''
and a separate thread to output ``"world.\n"''
Despite its brevity,
this example illustrates several points about programming with the
The argument types and the return type of
the printf (see
function disqualify it as the starting point of a thread.
A ``wrapper'' function (print) had to be devised.
There is no need for the initial thread to wait for the completion
of the two threads running print.
The process is automatically terminated after both of the printing
The use of
The use of return from main
or allowing main to run off the closing brace
is translated to a call to the
That system call generally terminates the process before the printing
threads can produce their output.
The order of the output is not guaranteed.
In most cases
the thread that is created first will be able to output ``"hello, "''
before the following thread outputs ``"world.\n"''
Occasionally, the order is reversed.
Basic threads management example
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004