pthread_create()

create thread 

Function


SYNOPSIS

#include <pthread.h>

int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(void *), void *arg);


DESCRIPTION

The pthread_create() function is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes are used (see pthread_attr_init()). If the attribute object is modified later, the thread's attributes are not affected. If thread is not NULL, pthread_create() stores the ID of the created thread in the location referenced by thread.

At creation, the thread executes start, with arg as its sole argument. The calling function must ensure that arg remains valid for the new thread throughout its lifetime. If start returns, the effect as if there was an implicit call to pthread_exit() using the return value of start as the exit status. Note that the thread in which main() was originally invoked differs from this. When it returns from main(), the effect as if there was an implicit call to exit() using the return value of main() as the exit status.

The signal state of the new thread is initialized as follows:

If pthread_create() fails, no new thread is created and the contents of the location referenced by thread are undefined.


PARAMETERS

thread 

Is the location where the ID of the newly created thread should be stored, or NULL if the thread ID is not required.

attr 

Is the thread attribute object specifying the attributes for the thread that is being created. If attr is NULL, the thread is created with default attributes.

start 

Is the main function for the thread; the thread begins executing user code at this address.

arg 

Is the argument passed to start.


RETURN VALUES

On success, pthread_create() returns 0. On error, one of the following values is returned:

EAGAIN 

The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process PTHREAD_THREADS_MAX would be exceeded.

EFAULT 

thread or attr is an invalid pointer.

EINVAL 

attr is not an initialized thread attribute object.


CONFORMANCE

POSIX P1003.1 (1996)


MULTITHREAD SAFETY LEVEL

MT-safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
exit(), pthread_attr_init(), pthread_exit(), pthread_join()


PTC MKS Toolkit 10.3 Documentation Build 39.