Pthread Join Linux Manual Page
User Manual:
Open the PDF directly: View PDF
.
Page Count: 3

9/15/2016 pthread_join(3)Linuxmanualpage
http://man7.org/linux/manpages/man3/pthread_join.3.html 1/3
man7.org>Linux>manpages Linux/UNIXsystemprogrammingtraining
NAME|SYNOPSIS|DESCRIPTION|RETURNVALUE|ERRORS|ATTRIBUTES|
CONFORMINGTO|NOTES|EXAMPLE|SEEALSO|COLOPHON
Searchonlinepages
PTHREAD_JOIN(3)LinuxProgrammer'sManualPTHREAD_JOIN(3)
NAMEtop
pthread_join‐joinwithaterminatedthread
SYNOPSIStop
#include<pthread.h>
intpthread_join(pthread_tthread,void**retval);
Compileandlinkwith‐pthread.
DESCRIPTIONtop
Thepthread_join()functionwaitsforthethreadspecifiedbythread
toterminate.Ifthatthreadhasalreadyterminated,then
pthread_join()returnsimmediately.Thethreadspecifiedbythread
mustbejoinable.
IfretvalisnotNULL,thenpthread_join()copiestheexitstatusof
thetargetthread(i.e.,thevaluethatthetargetthreadsuppliedto
pthread_exit(3))intothelocationpointedtoby*retval.Ifthe
targetthreadwascanceled,thenPTHREAD_CANCELEDisplacedin
*retval.
Ifmultiplethreadssimultaneouslytrytojoinwiththesamethread,
theresultsareundefined.Ifthethreadcallingpthread_join()is
canceled,thenthetargetthreadwillremainjoinable(i.e.,itwill
notbedetached).
RETURNVALUEtop
Onsuccess,pthread_join()returns0;onerror,itreturnsanerror
number.
ERRORStop
EDEADLK
Adeadlockwasdetected(e.g.,twothreadstriedtojoinwith

9/15/2016 pthread_join(3)Linuxmanualpage
http://man7.org/linux/manpages/man3/pthread_join.3.html 2/3
eachother);orthreadspecifiesthecallingthread.
EINVALthreadisnotajoinablethread.
EINVALAnotherthreadisalreadywaitingtojoinwiththisthread.
ESRCHNothreadwiththeIDthreadcouldbefound.
ATTRIBUTEStop
Foranexplanationofthetermsusedinthissection,see
attributes(7).
┌───────────────┬───────────────┬─────────┐
│Interface│Attribute│Value│
├───────────────┼───────────────┼─────────┤
│pthread_join()│Threadsafety│MT‐Safe│
└───────────────┴───────────────┴─────────┘
CONFORMINGTOtop
POSIX.1‐2001,POSIX.1‐2008.
NOTEStop
Afterasuccessfulcalltopthread_join(),thecallerisguaranteed
thatthetargetthreadhasterminated.
Joiningwithathreadthathaspreviouslybeenjoinedresultsin
undefinedbehavior.
Failuretojoinwithathreadthatisjoinable(i.e.,onethatisnot
detached),producesa"zombiethread".Avoiddoingthis,sinceeach
zombiethreadconsumessomesystemresources,andwhenenoughzombie
threadshaveaccumulated,itwillnolongerbepossibletocreatenew
threads(orprocesses).
Thereisnopthreadsanalogofwaitpid(‐1,&status,0),thatis,
"joinwithanyterminatedthread".Ifyoubelieveyouneedthis
functionality,youprobablyneedtorethinkyourapplicationdesign.
Allofthethreadsinaprocessarepeers:anythreadcanjoinwith
anyotherthreadintheprocess.
EXAMPLEtop
Seepthread_create(3).

9/15/2016 pthread_join(3)Linuxmanualpage
http://man7.org/linux/manpages/man3/pthread_join.3.html 3/3
SEEALSOtop
pthread_cancel(3),pthread_create(3),pthread_detach(3),
pthread_exit(3),pthread_tryjoin_np(3),pthreads(7)
COLOPHONtop
Thispageispartofrelease4.07oftheLinuxman‐pagesproject.A
descriptionoftheproject,informationaboutreportingbugs,andthe
latestversionofthispage,canbefoundat
https://www.kernel.org/doc/man‐pages/.
Linux2015‐07‐23PTHREAD_JOIN(3)
Copyrightandlicenseforthismanualpage
HTMLrenderingcreated20160901byMichaelKerrisk,authorofTheLinux
ProgrammingInterface,maintaineroftheLinuxmanpagesproject.
FordetailsofindepthLinux/UNIXsystemprogrammingtrainingcoursesthatI
teach,lookhere.
HostingbyjambitGmbH.