#include <pthread.h>
The pthread_create() function starts a new thread in the calling process. The new thread starts execution by invoking start_routine(); arg is passed as the sole argument of start_routine().
int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg);
PARAMETERS
thread
: point to buffer which will be saved the ID of new thread. on error, the contents of *thread are undefined.
attr
: The attr argument points to a pthread_attr_t structure whose contents are used at thread creation time to determine attributes for the new thread. If attr is NULL, then the thread is created with default attributes.
start_routine
: The function executing by new thread.
arg
: arg is passed as the sole argument of start_routine().
RETURN VALUE
: On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined.
The pthread_detach() function marks the thread identified by thread as detached. When a detached thread terminates, its resources are automatically released back to the system without the need for another thread to join with the terminated thread.
Once a thread has been detached, it can't be joined with pthread_join or be made joinable again.
A new thread can be created in a detached state using pthreadattr_setdetachstate to set the detached attribute of the attr argument of _pthread_create.
int pthread_detach(pthread_t thread);
RETURN VALUE
: On success, pthread_detach() returns 0; on error, it returns an error number.
The pthread_join() function waits for the thread specified by thread to terminate. If that thread has already terminated, then pthread_join() returns immediately. The thread specified by thread must be joinable.
int pthread_join(pthread_t thread, void **retval);
PARAMETERS
RETURN VALUE
: On success, pthread_join() returns 0; on error, it returns an error number.