Blame man2/set_tid_address.2

Packit 7cfc04
.\" Copyright (C) 2004 Andries Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH SET_TID_ADDRESS 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
set_tid_address \- set pointer to thread ID
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <linux/unistd.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "long set_tid_address(int *" tidptr );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.IR Note :
Packit 7cfc04
There is no glibc wrapper for this system call; see NOTES.
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
For each thread, the kernel maintains two attributes (addresses) called
Packit 7cfc04
.I set_child_tid
Packit 7cfc04
and
Packit 7cfc04
.IR clear_child_tid .
Packit 7cfc04
These two attributes contain the value NULL by default.
Packit 7cfc04
.TP
Packit 7cfc04
.I set_child_tid
Packit 7cfc04
If a thread is started using
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
with the
Packit 7cfc04
.B CLONE_CHILD_SETTID
Packit 7cfc04
flag,
Packit 7cfc04
.I set_child_tid
Packit 7cfc04
is set to the value passed in the
Packit 7cfc04
.I ctid
Packit 7cfc04
argument of that system call.
Packit 7cfc04
.IP
Packit 7cfc04
When
Packit 7cfc04
.I set_child_tid
Packit 7cfc04
is set, the very first thing the new thread does
Packit 7cfc04
is to write its thread ID at this address.
Packit 7cfc04
.TP
Packit 7cfc04
.I clear_child_tid
Packit 7cfc04
If a thread is started using
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
with the
Packit 7cfc04
.B CLONE_CHILD_CLEARTID
Packit 7cfc04
flag,
Packit 7cfc04
.I clear_child_tid
Packit 7cfc04
is set to the value passed in the
Packit 7cfc04
.I ctid
Packit 7cfc04
argument of that system call.
Packit 7cfc04
.PP
Packit 7cfc04
The system call
Packit 7cfc04
.BR set_tid_address ()
Packit 7cfc04
sets the
Packit 7cfc04
.I clear_child_tid
Packit 7cfc04
value for the calling thread to
Packit 7cfc04
.IR tidptr .
Packit 7cfc04
.PP
Packit 7cfc04
When a thread whose
Packit 7cfc04
.I clear_child_tid
Packit 7cfc04
is not NULL terminates, then,
Packit 7cfc04
if the thread is sharing memory with other threads,
Packit 7cfc04
then 0 is written at the address specified in
Packit 7cfc04
.I clear_child_tid
Packit 7cfc04
and the kernel performs the following operation:
Packit 7cfc04
.PP
Packit 7cfc04
    futex(clear_child_tid, FUTEX_WAKE, 1, NULL, NULL, 0);
Packit 7cfc04
.PP
Packit 7cfc04
The effect of this operation is to wake a single thread that
Packit 7cfc04
is performing a futex wait on the memory location.
Packit 7cfc04
Errors from the futex wake operation are ignored.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
.BR set_tid_address ()
Packit 7cfc04
always returns the caller's thread ID.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.BR set_tid_address ()
Packit 7cfc04
always succeeds.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
This call is present since Linux 2.5.48.
Packit 7cfc04
Details as given here are valid since Linux 2.5.49.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
This system call is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Glibc does not provide a wrapper for this system call; call it using
Packit 7cfc04
.BR syscall (2).
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR clone (2),
Packit 7cfc04
.BR futex (2),
Packit 7cfc04
.BR gettid (2)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.