man-pages/man3/pthread_tryjoin_np.3.html
2021-03-31 01:06:50 +01:00

245 lines
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of PTHREAD_TRYJOIN_NP</TITLE>
</HEAD><BODY>
<H1>PTHREAD_TRYJOIN_NP</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
pthread_tryjoin_np, pthread_timedjoin_np - try to join with a
terminated thread
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
<B>#include &lt;<A HREF="file:///usr/include/pthread.h">pthread.h</A>&gt;</B>
<B>int pthread_tryjoin_np(pthread_t </B><I>thread</I><B>, void **</B><I>retval</I><B>);</B>
<B>int pthread_timedjoin_np(pthread_t </B><I>thread</I><B>, void **</B><I>retval</I><B>,</B>
<B> const struct timespec *</B><I>abstime</I><B>);</B>
</PRE>
<P>
Compile and link with <I>-pthread</I>.
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These functions operate in the same way as
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3),
except for the differences described on this page.
<P>
The
<B>pthread_tryjoin_np</B>()
function performs a nonblocking join with the thread
<I>thread</I>,
returning the exit status of the thread in
<I>*retval</I>.
If
<I>thread</I>
has not yet terminated, then instead of blocking, as is done by
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3),
the call returns an error.
<P>
The
<B>pthread_timedjoin_np</B>()
function performs a join-with-timeout.
If
<I>thread</I>
has not yet terminated,
then the call blocks until a maximum time, specified in
<I>abstime</I>.
If the timeout expires before
<I>thread</I>
terminates,
the call returns an error.
The
<I>abstime</I>
argument is a structure of the following form,
specifying an absolute time measured since the Epoch (see
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2)):
<P>
struct timespec {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;time_t&nbsp;tv_sec;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;seconds&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;&nbsp;&nbsp;tv_nsec;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;nanoseconds&nbsp;*/
};
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
these functions return 0;
on error, they return an error number.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
These functions can fail with the same errors as
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3).
<B>pthread_tryjoin_np</B>()
can in addition fail with the following error:
<DL COMPACT>
<DT id="1"><B>EBUSY</B>
<DD>
<I>thread</I>
had not yet terminated at the time of the call.
</DL>
<P>
<B>pthread_timedjoin_np</B>()
can in addition fail with the following errors:
<DL COMPACT>
<DT id="2"><B>ETIMEDOUT</B>
<DD>
The call timed out before
<I>thread</I>
terminated.
<DT id="3"><B>EINVAL</B>
<DD>
<I>abstime</I>
value is invalid
(<I>tv_sec</I>
is less than 0 or
<I>tv_nsec</I>
is greater than 1e9).
</DL>
<P>
<B>pthread_timedjoin_np</B>()
never returns the error
<B>EINTR</B>.
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
These functions first appeared in glibc in version 2.3.3.
<A NAME="lbAH">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>pthread_tryjoin_np</B>(),
<B>pthread_timedjoin_np</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
These functions are nonstandard GNU extensions;
hence the suffix &quot;_np&quot; (nonportable) in the names.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
The following code waits to join for up to 5 seconds:
<P>
struct timespec ts;
int s;
<P>
...
<P>
if (clock_gettime(CLOCK_REALTIME, &amp;ts) == -1) {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Handle&nbsp;error&nbsp;*/
}
<P>
ts.tv_sec += 5;
<P>
s = pthread_timedjoin_np(thread, NULL, &amp;ts);
if (s != 0) {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Handle&nbsp;error&nbsp;*/
}
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+clock_gettime">clock_gettime</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_exit">pthread_exit</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+pthread_join">pthread_join</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+pthreads">pthreads</A></B>(7)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="10"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="11"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="12"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="13"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:53 GMT, March 31, 2021
</BODY>
</HTML>