| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_self 3 2025-05-17 "Linux man-pages 6.18" |
| 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 |
.P |
| 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 |
.TS |
| 35 |
allbox; |
| 36 |
lbx lb lb |
| 37 |
l l l. |
| 38 |
Interface Attribute Value |
| 39 |
T{ |
| 40 |
.na |
| 41 |
.nh |
| 42 |
.BR pthread_self () |
| 43 |
T} Thread safety MT-Safe |
| 44 |
.TE |
| 45 |
.SH STANDARDS |
| 46 |
POSIX.1-2008. |
| 47 |
.SH HISTORY |
| 48 |
POSIX.1-2001. |
| 49 |
.SH NOTES |
| 50 |
POSIX.1 allows an implementation wide freedom in choosing |
| 51 |
the type used to represent a thread ID; |
| 52 |
for example, representation using either an arithmetic type or |
| 53 |
a structure is permitted. |
| 54 |
Therefore, variables of type |
| 55 |
.I pthread_t |
| 56 |
can't portably be compared using the C equality operator |
| 57 |
.RB ( == ); |
| 58 |
use |
| 59 |
.BR pthread_equal (3) |
| 60 |
instead. |
| 61 |
.P |
| 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 |
.P |
| 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 |
.P |
| 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) |