Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)
pthread_create(2) OSS System Calls Reference Manual
• An executable thread is created with attributes specified by the attr parameter (or with
default attributes if attr is NULL).
Thread Creation
The system creates a thread in the ready state and prepares the thread to begin executing its start
routine, which is the function passed to pthread_create() as the start_routine parameter.
Depending on the presence of other threads and their scheduling and priority attributes, the new
thread might start executing immediately. The new thread can also preempt its creator, depend-
ing on the two threads’ respective scheduling and priority attributes. The caller of
pthread_create() can synchronize with the new thread using either the pthread_join( ) function
or any mutually agreed upon mutexes or condition variables.
For the duration of the new thread’s existence, the system maintains and manages the thread
object and other thread state overhead.
The system assigns each new thread a thread identifier, which the system writes into the address
specified by the thread parameter before the new thread executes.
At thread creation, the scheduling policy and scheduling parameters stored in the thread attri-
butes object passed to pthread_create() is used by default. If you want the scheduling attributes
to be inherited from the parent thread, then before creating the new thread your program must use
the pthread_attr_setinheritsched() function with the inheritsched parameter set to
PTHREAD_INHERIT_SCHED.
The signal state of the new thread is initialized as follows:
• The signal mask is inherited from the creating thread.
• The set of signals pending for the new thread is empty.
If pthread_create() fails, no new thread is created and the contents of the location indicated by
the thread parameter are undefined.
Thread Termination
A thread terminates when one of the following occurs:
• The thread returns from its start routine.
• The thread calls the pthread_exit( ) function.
• The thread is canceled.
When a thread terminates, the system performs these actions:
• The system writes a return value (if one is available) into the terminated thread’s attri-
butes object, as follows:
— If the thread has been canceled, the system writes the value
PTHREAD_CANCELED into the object specified by attr.
— If the thread terminated by returning from its start routine, the system copies the
return value from the start routine (if one is available) into the object specified
by attr.
— If the thread explictly called the pthread_exit( ) function, the system stores the
value received in the value_ptr parameter of pthread_exit() into the object
specified by attr.
Another thread can obtain this return value by joining with the terminated thread using
the pthread_join() function. If the thread terminated by returning from its start routine
5−102 Hewlett-Packard Company 527186-023