1PTHREAD_SELF(3)            Linux Programmer's Manual           PTHREAD_SELF(3)
2
3
4

NAME

6       pthread_self - obtain ID of the calling thread
7

SYNOPSIS

9       #include <pthread.h>
10
11       pthread_t pthread_self(void);
12
13       Compile and link with -pthread.
14

DESCRIPTION

16       The pthread_self() function returns the ID of the calling thread.  This
17       is the same value that is returned in *thread in the  pthread_create(3)
18       call that created this thread.
19

RETURN VALUE

21       This function always succeeds, returning the calling thread's ID.
22

ERRORS

24       This function always succeeds.
25

ATTRIBUTES

27       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
28       tributes(7).
29
30       ┌────────────────────────────────────────────┬───────────────┬─────────┐
31Interface                                   Attribute     Value   
32       ├────────────────────────────────────────────┼───────────────┼─────────┤
33pthread_self()                              │ Thread safety │ MT-Safe │
34       └────────────────────────────────────────────┴───────────────┴─────────┘
35

CONFORMING TO

37       POSIX.1-2001, POSIX.1-2008.
38

NOTES

40       POSIX.1 allows an implementation wide freedom in choosing the type used
41       to  represent  a thread ID; for example, representation using either an
42       arithmetic type or a structure is permitted.  Therefore,  variables  of
43       type pthread_t can't portably be compared using the C equality operator
44       (==); use pthread_equal(3) instead.
45
46       Thread identifiers should be considered opaque: any attempt  to  use  a
47       thread  ID  other than in pthreads calls is nonportable and can lead to
48       unspecified results.
49
50       Thread IDs are guaranteed to be unique only within a process.  A thread
51       ID  may  be  reused after a terminated thread has been joined, or a de‐
52       tached thread has terminated.
53
54       The thread ID returned by pthread_self() is not the same thing  as  the
55       kernel thread ID returned by a call to gettid(2).
56

SEE ALSO

58       pthread_create(3), pthread_equal(3), pthreads(7)
59

COLOPHON

61       This  page  is  part of release 5.12 of the Linux man-pages project.  A
62       description of the project, information about reporting bugs,  and  the
63       latest     version     of     this    page,    can    be    found    at
64       https://www.kernel.org/doc/man-pages/.
65
66
67
68Linux                             2021-03-22                   PTHREAD_SELF(3)
Impressum