pthread_join - Online Linux Manual PageSection : 3
Updated : 2022-12-15
Source : Linux man-pages 6.03

NAMEpthread_join − join with a terminated thread

LIBRARYPOSIX threads library (libpthread, −lpthread)

SYNOPSIS#include <pthread.h>int pthread_join(pthread_t thread, void **retval);

DESCRIPTIONThe 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. If retval is not NULL, then pthread_join() copies the exit status of the target thread (i.e., the value that the target thread supplied to pthread_exit(3)) 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. If multiple threads simultaneously try to join with the same thread, the results are undefined. If the thread calling pthread_join() is canceled, then the target thread will remain joinable (i.e., it will not be detached).

RETURN VALUEOn success, pthread_join() returns 0; on error, it returns an error number.

ERRORSEDEADLK  A deadlock was detected (e.g., two threads tried to join with each other); or thread specifies the calling thread. EINVAL  thread is not a joinable thread. EINVAL  Another thread is already waiting to join with this thread. ESRCH  No thread with the ID thread could be found.

ATTRIBUTESFor an explanation of the terms used in this section, see attributes(7). InterfaceAttributeValue pthread_join() Thread safetyMT-Safe

STANDARDSPOSIX.1-2001, POSIX.1-2008.

NOTESAfter a successful call to pthread_join(), the caller is guaranteed that the target thread has terminated. The caller may then choose to do any clean-up that is required after termination of the thread (e.g., freeing memory or other resources that were allocated to the target thread). Joining with a thread that has previously been joined results in undefined behavior. Failure to join with a thread that is joinable (i.e., one that is not detached), produces a "zombie thread". Avoid doing this, since each zombie thread consumes some system resources, and when enough zombie threads have accumulated, it will no longer be possible to create new threads (or processes). There is no pthreads analog of waitpid(−1, &status, 0), that is, "join with any terminated thread". If you believe you need this functionality, you probably need to rethink your application design. All of the threads in a process are peers: any thread can join with any other thread in the process.

EXAMPLESSee pthread_create(3).

SEE ALSOpthread_cancel(3), pthread_create(3), pthread_detach(3), pthread_exit(3), pthread_tryjoin_np(3), pthreads(7)
0
Johanes Gumabo
Data Size   :   10,948 byte
man-pthread_join.3Build   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   4 / 183,998
Visitor ID   :     :  
Visitor IP   :   3.139.79.187   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.