pthread_create.3t (2010 09)

p
pthread_create(3T) pthread_create(3T)
(Pthread Library)
NAME
pthread_create() - create a new thread of execution.
SYNOPSIS
#include <pthread.h>
int pthread_create(
pthread_t *__restrict thread,
const pthread_attr_t *__restrict attr,
void *(*start_routine)(void *),
void *__restrict arg
);
PARAMETERS
thread Pointer to the location where the created thread’s ID is to be returned.
attr Pointer to the thread attributes object describing the characteristics of the created
thread. If the value is NULL, default attributes will be used.
start_routine
Function to be executed by the newly created thread.
arg Parameter to be passed to the created threads start_routine.
DESCRIPTION
The
pthread_create()
function is used to create a new independent thread within the calling pro-
cess. The thread will be created according to the attributes specified by attr .Ifattr is NULL, the default
attributes will be used. The values of the attributes in attr describe the characteristics of the to-be-
created thread in detail. Refer to the function
pthread_attr_init()
for a list of the default attri-
bute values. A single attributes object can be used in multiple calls to the function
pthread_create().
When a thread is created with an attributes object, the attributes are, in effect, copied into the created
thread. Consequently, any change to the attributes object will not affect any previously created threads.
Once all threads needing a specific attributes object have been created, the attributes object is no longer
needed and may be destroyed.
When the new thread is created, it will execute
start_routine()
, which has only one parameter, arg.
If
start_routine()
returns, an implicit call to pthread_exit() is made. The return value of
start_routine() is used as the threads exit status.
The created thread’s scheduling policy and priority, contention scope, detach state, stack size, and stack
address are initialized according to their respective attributes in attr . The thread’s signal mask is inher-
ited from the creating thread. The threads set of pending signals is cleared.
Refer to pthread_exit (3T), pthread_detach(3T), and pthread_join (3T) for more information on thread ter-
mination and synchronizing with terminated threads.
On success, the ID of the created thread is returned in thread .If
pthread_create() fails, a thread is
not created and the contents of thread are undefined.
Thread IDs are guaranteed to be unique only within a process.
NOTE: If the main thread returns from
main(), an implicit call to exit() is made. The return value of
main() is used as the process exit status. The main thread can terminate without causing the process to
terminate by calling pthread_exit().
Notes
It is unspecified whether joinable threads that have exited but havent been joined count against the
PTHREAD_THREADS_MAX limit.
RETURN VALUE
Upon successful completion,
pthread_create() returns zero. Otherwise, an error number is returned
to indicate the error (the errno variable is not set).
ERRORS
If any of the following occur, the
pthread_create() function returns the corresponding error number:
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)