Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

pthread_create(3) [redhat man page]

PTHREAD_CREATE(3)					     Library Functions Manual						 PTHREAD_CREATE(3)

NAME
pthread_create - create a new thread SYNOPSIS
#include <pthread.h> int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void * arg); DESCRIPTION
pthread_create creates a new thread of control that executes concurrently with the calling thread. The new thread applies the function start_routine passing it arg as first argument. The new thread terminates either explicitly, by calling pthread_exit(3), or implicitly, by returning from the start_routine function. The latter case is equivalent to calling pthread_exit(3) with the result returned by start_rou- tine as exit code. The attr argument specifies thread attributes to be applied to the new thread. See pthread_attr_init(3) for a complete list of thread attributes. The attr argument can also be NULL, in which case default attributes are used: the created thread is joinable (not detached) and has default (non real-time) scheduling policy. RETURN VALUE
On success, the identifier of the newly created thread is stored in the location pointed by the thread argument, and a 0 is returned. On error, a non-zero error code is returned. ERRORS
EAGAIN not enough system resources to create a process for the new thread. EAGAIN more than PTHREAD_THREADS_MAX threads are already active. AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
pthread_exit(3), pthread_join(3), pthread_detach(3), pthread_attr_init(3). LinuxThreads PTHREAD_CREATE(3)

Check Out this Related Man Page

PTHREAD_JOIN(3) 					     Library Functions Manual						   PTHREAD_JOIN(3)

NAME
pthread_join - wait for termination of another thread SYNOPSIS
#include <pthread.h> int pthread_join(pthread_t th, void **thread_return); DESCRIPTION
pthread_join suspends the execution of the calling thread until the thread identified by th terminates, either by calling pthread_exit(3) or by being cancelled. If thread_return is not NULL, the return value of th is stored in the location pointed to by thread_return. The return value of th is either the argument it gave to pthread_exit(3), or PTHREAD_CANCELED if th was cancelled. The joined thread th must be in the joinable state: it must not have been detached using pthread_detach(3) or the PTHREAD_CREATE_DETACHED attribute to pthread_create(3). When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks. At most one thread can wait for the termination of a given thread. Calling pthread_join on a thread th on which another thread is already waiting for termination returns an error. CANCELLATION
pthread_join is a cancellation point. If a thread is canceled while suspended in pthread_join, the thread execution resumes immediately and the cancellation is executed without waiting for the th thread to terminate. If cancellation occurs during pthread_join, the th thread remains not joined. RETURN VALUE
On success, the return value of th is stored in the location pointed to by thread_return, and 0 is returned. On error, a non-zero error code is returned. ERRORS
ESRCH No thread could be found corresponding to that specified by th. EINVAL The th thread has been detached. EINVAL Another thread is already waiting on termination of th. EDEADLK The th argument refers to the calling thread. AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
pthread_exit(3), pthread_detach(3), pthread_create(3), pthread_attr_setdetachstate(3), pthread_cleanup_push(3), pthread_key_create(3). LinuxThreads PTHREAD_JOIN(3)
Man Page