1.\" Copyright (c) 2016 The FreeBSD Foundation, Inc. 2.\" 3.\" This documentation was written by 4.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship 5.\" from the FreeBSD Foundation. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd May 5, 2020 29.Dt THR_SELF 2 30.Os 31.Sh NAME 32.Nm thr_self 33.Nd return thread identifier for the calling thread 34.Sh LIBRARY 35.Lb libc 36.Sh SYNOPSIS 37.In sys/thr.h 38.Ft int 39.Fn thr_self "long *id" 40.Sh DESCRIPTION 41The 42.Fn thr_self 43system call stores the system-wide thread identifier for the current 44kernel-scheduled thread in the variable pointed by the argument 45.Va id . 46.Pp 47The thread identifier is an integer in the range from 48.Dv PID_MAX + 2 49(100001) to 50.Dv INT_MAX . 51The thread identifier is guaranteed to be unique at any given time, 52for each running thread in the system. 53After the thread exits, the identifier may be reused. 54.Sh RETURN VALUES 55If successful, 56.Fn thr_self 57will return zero, otherwise \-1 is returned, and 58.Va errno 59is set to indicate the error. 60.Sh ERRORS 61The 62.Fn thr_self 63operation may return the following errors: 64.Bl -tag -width Er 65.It Bq Er EFAULT 66The memory pointed to by the 67.Fa id 68argument is not valid. 69.El 70.Sh SEE ALSO 71.Xr _umtx_op 2 , 72.Xr thr_exit 2 , 73.Xr thr_kill 2 , 74.Xr thr_kill2 2 , 75.Xr thr_new 2 , 76.Xr thr_set_name 2 , 77.Xr pthread_getthreadid_np 3 , 78.Xr pthread_self 3 79.Sh STANDARDS 80The 81.Fn thr_self 82system call is non-standard and is used by 83.Lb libthr 84to implement 85.St -p1003.1-2001 86.Xr pthread 3 87functionality. 88.Sh HISTORY 89The 90.Fn thr_self 91system call first appeared in 92.Fx 5.2 . 93