1pthread_self(3)            Library Functions Manual            pthread_self(3)
2
3
4

NAME

6       pthread_self - obtain ID of the calling thread
7

LIBRARY

9       POSIX threads library (libpthread, -lpthread)
10

SYNOPSIS

12       #include <pthread.h>
13
14       pthread_t pthread_self(void);
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

25       This function always succeeds.
26

ATTRIBUTES

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

STANDARDS

38       POSIX.1-2008.
39

HISTORY

41       POSIX.1-2001.
42

NOTES

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

SEE ALSO

62       pthread_create(3), pthread_equal(3), pthreads(7)
63
64
65
66Linux man-pages 6.04              2023-03-30                   pthread_self(3)
Impressum