The pthread_create function

Name

pthread_create -- 

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:

EAGAIN if there is insufficient memory to create another thread
ENOMEM if there is insufficient memory for the thread's stack
EINVAL if a value specified by attr is invalid

Implementation Notes

The function pthread_create calls calloc to allocate memory for the thread's data, and calls malloc to allocates the thread's stack.

See Also

The pthread_exit function
The pthread_join function