PTHREAD_CREATE(3P) SysV PTHREAD_CREATE(3P)
NAME
pthread_create - Creates a thread
SYNOPSIS
#include <pthread.h>
int pthread_create (thread, attr, start_routine, arg)
pthread_t *thread;
pthread_attr_t attr;
void *( *start_routine) (void *arg);
void *arg;
DESCRIPTION
The pthread_create function creates a new thread, with attributes
specified by the attr argument. If attr is pthread_attr_default, the
default attributes are used.
The arguments are as follows:
thread Specifies the address in which the ID for the new thread will
be stored.
attr Specifies the address of the attributes object to use in
creating the new thread.
start_routine
Specifies the address of the routine to be executed by the new
thread.
arg Specifies the single argument to be passed to the start_routine
argument.
The thread is created executing start_routine, with arg as its sole
argument. If start_routine returns, an implicit call to the
pthread_exit(3P) function is made using the return value of start_routine
as the exit status.
Variables accessible to one thread in a process are available to all
other threads in that process. Use the pthread_mutex_init(3P) function
to create a mutex for controlling access to shared data. Use the
pthread_keycreate(3P) function to create a key for accessing thread-
specific data.
Each thread has its own cancelability state, which determines the
thread's response to a cancellation request (that is, whether or not the
thread can be canceled, and when it can be canceled). There are two
types of cancelability: general cancelability (which is set with
pthread_setcancel(3P) function), and asynchronous cancelability (which is
set with pthread_setasynccancel(3P) function). They work together to
determine a thread's cancelability state. When a thread is created,
general cancelability is enabled and asynchronous cancelability is
disabled, which means that the thread can only be canceled at
cancellation points.
NOTES
This interface is based on draft 4 of the IEEE P1003.4a standard, and
will be changed to conform to the final version.
DIAGNOSTICS
Upon successful completion, the ID of the created thread is stored at
*thread, and a value of 0 (zero) is returned. Otherwise, no thread is
created, -1 is returned, and errno is set to indicate the error.
ERRORS
If the pthread_create function fails, errno may be set to one of the
following values:
[EAGAIN] The system lacks the resources necessary to create another
thread.
[EAGAIN] The new thread cannot be created without exceeding the system-
imposed limit on the total number of threads allowed for each
user.
[ENOMEM] There is not enough memory to create the thread. This is not a
temporary condition.
[EINVAL] The value specified by the thread or attr argument is invalid.
SEE ALSO
fork(2), pthread_exit(3P), pthread_join(3P)