Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / set_tid_address.2
blob1f4b4d20575061993565f10daeecf4d71a5f0067
1 .\" Copyright (C) 2004 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH SET_TID_ADDRESS 2 2021-06-20 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 set_tid_address \- set pointer to thread ID
28 .SH SYNOPSIS
29 .nf
30 .BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
31 .B #include <unistd.h>
32 .PP
33 .BI "pid_t syscall(SYS_set_tid_address, int *" tidptr );
34 .fi
35 .PP
36 .IR Note :
37 glibc provides no wrapper for
38 .BR set_tid_address (),
39 necessitating the use of
40 .BR syscall (2).
41 .SH DESCRIPTION
42 For each thread, the kernel maintains two attributes (addresses) called
43 .I set_child_tid
44 and
45 .IR clear_child_tid .
46 These two attributes contain the value NULL by default.
47 .TP
48 .I set_child_tid
49 If a thread is started using
50 .BR clone (2)
51 with the
52 .B CLONE_CHILD_SETTID
53 flag,
54 .I set_child_tid
55 is set to the value passed in the
56 .I ctid
57 argument of that system call.
58 .IP
59 When
60 .I set_child_tid
61 is set, the very first thing the new thread does
62 is to write its thread ID at this address.
63 .TP
64 .I clear_child_tid
65 If a thread is started using
66 .BR clone (2)
67 with the
68 .B CLONE_CHILD_CLEARTID
69 flag,
70 .I clear_child_tid
71 is set to the value passed in the
72 .I ctid
73 argument of that system call.
74 .PP
75 The system call
76 .BR set_tid_address ()
77 sets the
78 .I clear_child_tid
79 value for the calling thread to
80 .IR tidptr .
81 .PP
82 When a thread whose
83 .I clear_child_tid
84 is not NULL terminates, then,
85 if the thread is sharing memory with other threads,
86 then 0 is written at the address specified in
87 .I clear_child_tid
88 and the kernel performs the following operation:
89 .PP
90     futex(clear_child_tid, FUTEX_WAKE, 1, NULL, NULL, 0);
91 .PP
92 The effect of this operation is to wake a single thread that
93 is performing a futex wait on the memory location.
94 Errors from the futex wake operation are ignored.
95 .SH RETURN VALUE
96 .BR set_tid_address ()
97 always returns the caller's thread ID.
98 .SH ERRORS
99 .BR set_tid_address ()
100 always succeeds.
101 .SH VERSIONS
102 This call is present since Linux 2.5.48.
103 Details as given here are valid since Linux 2.5.49.
104 .SH CONFORMING TO
105 This system call is Linux-specific.
106 .SH SEE ALSO
107 .BR clone (2),
108 .BR futex (2),
109 .BR gettid (2)