man-pages/man2/set_tid_address.2.html
2021-03-31 01:06:50 +01:00

178 lines
4.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SET_TID_ADDRESS</TITLE>
</HEAD><BODY>
<H1>SET_TID_ADDRESS</H1>
Section: Linux Programmer's Manual (2)<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>
set_tid_address - set pointer to thread ID
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/linux/unistd.h">linux/unistd.h</A>&gt;</B>
<B>long set_tid_address(int *</B><I>tidptr</I><B>);</B>
</PRE>
<P>
<I>Note</I>:
There is no glibc wrapper for this system call; see NOTES.
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
For each thread, the kernel maintains two attributes (addresses) called
<I>set_child_tid</I>
and
<I>clear_child_tid</I>.
These two attributes contain the value NULL by default.
<DL COMPACT>
<DT id="1"><I>set_child_tid</I>
<DD>
If a thread is started using
<B><A HREF="/cgi-bin/man/man2html?2+clone">clone</A></B>(2)
with the
<B>CLONE_CHILD_SETTID</B>
flag,
<I>set_child_tid</I>
is set to the value passed in the
<I>ctid</I>
argument of that system call.
<DT id="2"><DD>
When
<I>set_child_tid</I>
is set, the very first thing the new thread does
is to write its thread ID at this address.
<DT id="3"><I>clear_child_tid</I>
<DD>
If a thread is started using
<B><A HREF="/cgi-bin/man/man2html?2+clone">clone</A></B>(2)
with the
<B>CLONE_CHILD_CLEARTID</B>
flag,
<I>clear_child_tid</I>
is set to the value passed in the
<I>ctid</I>
argument of that system call.
</DL>
<P>
The system call
<B>set_tid_address</B>()
sets the
<I>clear_child_tid</I>
value for the calling thread to
<I>tidptr</I>.
<P>
When a thread whose
<I>clear_child_tid</I>
is not NULL terminates, then,
if the thread is sharing memory with other threads,
then 0 is written at the address specified in
<I>clear_child_tid</I>
and the kernel performs the following operation:
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;futex(clear_child_tid,&nbsp;FUTEX_WAKE,&nbsp;1,&nbsp;NULL,&nbsp;NULL,&nbsp;0);
<P>
The effect of this operation is to wake a single thread that
is performing a futex wait on the memory location.
Errors from the futex wake operation are ignored.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>set_tid_address</B>()
always returns the caller's thread ID.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<B>set_tid_address</B>()
always succeeds.
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
This call is present since Linux 2.5.48.
Details as given here are valid since Linux 2.5.49.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
This system call is Linux-specific.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Glibc does not provide a wrapper for this system call; call it using
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+clone">clone</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+futex">futex</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+gettid">gettid</A></B>(2)
<A NAME="lbAK">&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">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
<DT id="12"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="13"><A HREF="#lbAK">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:34 GMT, March 31, 2021
</BODY>
</HTML>