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