14.2. Create and Destroy Functions

14.2.1. The pthread_create function

Synopsis
#include <pthread.h>

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

Description

The pthread_create function creates a thread with the attributes specified in attr. If attr is NULL then the default attributes are used. The new thread starts execution in start_routine, which is passed the single specified argument.

Returns

If the pthread_create function succeeds it returns 0 and puts the new thread id into thread, otherwise it returns -1 and sets an error number as follows:

Implementation Notes
See Also
Section 14.2.4
Section 14.2.5

14.2.2. The pthread_detach function

Synopsis
#include <pthread.h>

int pthread_detach (pthread_t * thread_ptr );

Description

The pthread_detach function marks the threads's internal data structure for deletion.

Returns

The pthread_detach function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

None.

14.2.3. The pthread_equal function

Synopsis
#include <pthread.h>

int pthread_equal (pthread_t t1 , pthread_t t2 );

Description

The pthread_equal function compares the two threads t1 and t2.

Returns

The pthread_equal function returns one if the two threads are the same thread, and zero otherwise.

Implementation Notes

None.

14.2.4. The pthread_exit function

Synopsis
#include <pthread.h>

void pthread_exit (any_t status );

Description

The pthread_exit function terminates the calling thread returning the value given by status to any thread that has called pthread_join for the calling thread.

Returns

The pthread_exit function returns no value.

Implementation Notes

None.

14.2.5. The pthread_join function

Synopsis
#include <pthread.h>

int pthread_join (pthread_t thread , any_t * status );

Description

The pthread_join function causes the calling thread to wait for the given thread's termination. If the parameter status is not null then it receives the return value of the terminating thread.

Returns

The pthread_join function returns zero if the call is successful, otherwise it sets errno to EINVAL and returns -1.

Implementation Notes

None.