NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |ATTRIBUTES |STANDARDS |HISTORY |BUGS |EXAMPLES |SEE ALSO |COLOPHON | |
pthread_tryjoin_np(3) Library Functions Manualpthread_tryjoin_np(3)pthread_tryjoin_np, pthread_timedjoin_np - try to join with a terminated thread
POSIX threads library (libpthread,-lpthread)
#define _GNU_SOURCE/* See feature_test_macros(7) */#include <pthread.h>int pthread_tryjoin_np(pthread_tthread, void **retval);int pthread_timedjoin_np(pthread_tthread, void **retval,const struct timespec *abstime);
These functions operate in the same way aspthread_join(3), except for the differences described on this page. Thepthread_tryjoin_np() function performs a nonblocking join with the threadthread, returning the exit status of the thread in*retval. Ifthread has not yet terminated, then instead of blocking, as is done bypthread_join(3), the call returns an error. Thepthread_timedjoin_np() function performs a join-with-timeout. Ifthread has not yet terminated, then the call blocks until a maximum time, specified inabstime, measured against theCLOCK_REALTIMEclock. If the timeout expires beforethread terminates, the call returns an error. Theabstime argument is atimespec(3) structure, specifying an absolute time measured since the Epoch (seetime(2)).
On success, these functions return 0; on error, they return an error number.
These functions can fail with the same errors aspthread_join(3).pthread_tryjoin_np() can in addition fail with the following error:EBUSYthread had not yet terminated at the time of the call.pthread_timedjoin_np() can in addition fail with the following errors:EINVALabstime value is invalid (tv_sec is less than 0 ortv_nsec is greater than 1e9).ETIMEDOUT The call timed out beforethread terminated.pthread_timedjoin_np() never returns the errorEINTR.
For an explanation of the terms used in this section, seeattributes(7). ┌──────────────────────────────────────┬───────────────┬─────────┐ │Interface│Attribute│Value│ ├──────────────────────────────────────┼───────────────┼─────────┤ │pthread_tryjoin_np(), │ Thread safety │ MT-Safe │ │pthread_timedjoin_np() │ │ │ └──────────────────────────────────────┴───────────────┴─────────┘
GNU; hence the suffix "_np" (nonportable) in the names.
glibc 2.3.3.
Thepthread_timedjoin_np() function measures time by internally calculating a relative sleep interval that is then measured against theCLOCK_MONOTONICclock instead of theCLOCK_REALTIME clock. Consequently, the timeout is unaffected by discontinuous changes to theCLOCK_REALTIMEclock.
The following code waits to join for up to 5 seconds: struct timespec ts; int s; ... if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { /* Handle error */ } ts.tv_sec += 5; s = pthread_timedjoin_np(thread, NULL, &ts); if (s != 0) { /* Handle error */ }clock_gettime(2),pthread_exit(3),pthread_join(3),timespec(3),pthreads(7)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-05-17pthread_tryjoin_np(3)Pages that refer to this page:pthread_join(3)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |