[man] pthread_*

숭글·2022년 9월 12일
0

#include <pthread.h>

pthread_create()

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.


pthread_detach

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.


pthread_join

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

  • retval
    : If retval is not NULL, then pthread_join() copies the exit status of the target thread into the location pointed to by retval. If the target thread was canceled, then PTHREAD_CANCELED is placed in the location pointed to by retval.

RETURN VALUE
: On success, pthread_join() returns 0; on error, it returns an error number.


📖 pthread_create
📖 pthread_detach
📖 pthread_join

profile
Hi!😁 I'm Soongle. Welcome to my Velog!!!

0개의 댓글