36.2.1 Creating and Destroying Threads

Function: int pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)

This function creates a new thread with attributes attr. This thread will call start_routine and pass it arg. If start_routine returns, the thread will exit and the return value will become the thread’s exit value. The new thread’s ID is stored in newthread. Returns 0 on success. This documentation is a stub. For additional information on this function, consult the manual page pthread_create(3) See Linux (The Linux Kernel).

Function: int pthread_detach (pthread_t th)

Indicates that thread th must clean up after itself automatically when it exits, as the parent thread will not call pthread_join on it. This documentation is a stub. For additional information on this function, consult the manual page pthread_detach(3) See Linux (The Linux Kernel).

Function: int pthread_join (pthread_t th, void **thread_return)

Waits for thread th to exit, and stores its return value in thread_return. This documentation is a stub. For additional information on this function, consult the manual page pthread_join(3) See Linux (The Linux Kernel).

Function: int pthread_kill (pthread_t th, int signal)

Sends signal signal to thread th. This documentation is a stub. For additional information on this function, consult the manual page pthread_kill(3) See Linux (The Linux Kernel).

Function: pthread_t pthread_self (void)

Returns the ID of the thread which performed the call. This documentation is a stub. For additional information on this function, consult the manual page pthread_self(3) See Linux (The Linux Kernel).

Each thread has a set of attributes which are passed to pthread_create via the pthread_attr_t type, which should be considered an opaque type.

Function: int pthread_attr_init (pthread_attr_t *attr)

Initializes attr to its default values and allocates any resources required. Once initialized, attr can be modified by other pthread_attr_* functions, or used by pthread_create. This documentation is a stub. For additional information on this function, consult the manual page pthread_attr_init(3) See Linux (The Linux Kernel).

Function: int pthread_attr_destroy (pthread_attr_t *attr)

When no longer needed, attr should be destroyed with this function, which releases any resources allocated. Note that attr is only needed for the pthread_create call, not for the running thread itself. This documentation is a stub. For additional information on this function, consult the manual page pthread_attr_destroy(3) See Linux (The Linux Kernel).

Function: int pthread_attr_setdetachstate (pthread_attr_t *attr, int detachstate)

Sets the detach state attribute for attr. This attribute may be one of the following:

PTHREAD_CREATE_DETACHED

Causes the created thread to be detached, that is, as if pthread_detach had been called on it.

PTHREAD_CREATE_JOINABLE

Causes the created thread to be joinable, that is, pthread_join must be called on it.

This documentation is a stub. For additional information on this function, consult the manual page pthread_attr_setdetachstate(3) See Linux (The Linux Kernel).

Function: int pthread_attr_getdetachstate (const pthread_attr_t *attr, int *detachstate)

Gets the detach state attribute from attr. This documentation is a stub. For additional information on this function, consult the manual page pthread_attr_getdetachstate(3) See Linux (The Linux Kernel).