]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_self.3
5e6080451b4499fa8db1ee270179c113aecee952
[thirdparty/man-pages.git] / man3 / pthread_self.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH PTHREAD_SELF 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
7 .SH NAME
8 pthread_self \- obtain ID of the calling thread
9 .SH LIBRARY
10 POSIX threads library
11 .RI ( libpthread ", " \-lpthread )
12 .SH SYNOPSIS
13 .nf
14 .B #include <pthread.h>
15 .PP
16 .B pthread_t pthread_self(void);
17 .fi
18 .SH DESCRIPTION
19 The
20 .BR pthread_self ()
21 function returns the ID of the calling thread.
22 This is the same value that is returned in
23 .I *thread
24 in the
25 .BR pthread_create (3)
26 call that created this thread.
27 .SH RETURN VALUE
28 This function always succeeds, returning the calling thread's ID.
29 .SH ERRORS
30 This function always succeeds.
31 .SH ATTRIBUTES
32 For an explanation of the terms used in this section, see
33 .BR attributes (7).
34 .ad l
35 .nh
36 .TS
37 allbox;
38 lbx lb lb
39 l l l.
40 Interface Attribute Value
41 T{
42 .BR pthread_self ()
43 T} Thread safety MT-Safe
44 .TE
45 .hy
46 .ad
47 .sp 1
48 .SH STANDARDS
49 POSIX.1-2001, POSIX.1-2008.
50 .SH NOTES
51 POSIX.1 allows an implementation wide freedom in choosing
52 the type used to represent a thread ID;
53 for example, representation using either an arithmetic type or
54 a structure is permitted.
55 Therefore, variables of type
56 .I pthread_t
57 can't portably be compared using the C equality operator (\fB==\fP);
58 use
59 .BR pthread_equal (3)
60 instead.
61 .PP
62 Thread identifiers should be considered opaque:
63 any attempt to use a thread ID other than in pthreads calls
64 is nonportable and can lead to unspecified results.
65 .PP
66 Thread IDs are guaranteed to be unique only within a process.
67 A thread ID may be reused after a terminated thread has been joined,
68 or a detached thread has terminated.
69 .PP
70 The thread ID returned by
71 .BR pthread_self ()
72 is not the same thing as the kernel thread ID returned by a call to
73 .BR gettid (2).
74 .SH SEE ALSO
75 .BR pthread_create (3),
76 .BR pthread_equal (3),
77 .BR pthreads (7)