xref: /freebsd/share/man/man3/pthread_attr_get_np.3 (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1.\" Copyright (c) 2002,2003 Alexey Zelkin <phantom@FreeBSD.org>
2.\" All rights reserved.
3.\" Copyright (c) 2024 The FreeBSD Foundation
4.\"
5.\" Portions of this documentation were written by Olivier Certner
6.\" <olce@FreeBSD.org> at Kumacom SARL under sponsorship from the
7.\" FreeBSD Foundation.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd January 5, 2024
31.Dt PTHREAD_ATTR_GET_NP 3
32.Os
33.Sh NAME
34.Nm pthread_attr_get_np
35.Nd get attributes of an existing thread
36.Sh LIBRARY
37.Lb libpthread
38.Sh SYNOPSIS
39.In pthread_np.h
40.Ft int
41.Fn pthread_attr_get_np "pthread_t pid" "pthread_attr_t *dst"
42.Sh DESCRIPTION
43The
44.Fn pthread_attr_get_np
45function is used to retrieve the attributes of the specified thread into an
46existing
47.Vt pthread_attr_t
48structure.
49The attributes' values are the current ones for the target thread, except for
50the stack top address if not properly aligned for the architecture, since in
51this case its value has been adjusted internally before use.
52.Pp
53Argument
54.Fa dst
55must be a pointer to a valid attributes object
56.Po
57it was initialized at some point by
58.Xr pthread_attr_init 3
59and was not destroyed since then
60.Pc .
61After a successful call to
62.Fn pthread_attr_get_np ,
63the individual attributes' values can be retrieved as usual via the
64corresponding accessor functions as documented in
65.Xr pthread_attr 3 .
66After a failed call to
67.Fn pthread_attr_get_np ,
68the object pointed to by
69.Fa dst
70is left unmodified, and can continue to be used as if the failed call never
71happened.
72.Sh RETURN VALUES
73If successful,
74.Fn pthread_attr_get_np
75function returns 0.
76Otherwise, an error number is returned to indicate the error.
77.Sh EXAMPLES
78This function retrieves the stack size of the thread specified by the
79.Fa pid
80argument:
81.Bd -literal
82size_t
83my_thread_stack_size(pthread_t tid)
84{
85	pthread_attr_t attr;
86	size_t size;
87
88	pthread_attr_init(&attr);
89	pthread_attr_get_np(tid, &attr);
90	pthread_attr_getstacksize(&attr, &size);
91	pthread_attr_destroy(&attr);
92	return (size);
93}
94.Ed
95.Sh ERRORS
96The
97.Fn pthread_attr_get_np
98function will fail if:
99.Bl -tag -width Er
100.It Bq Er EINVAL
101One of the arguments has an invalid value.
102.It Bq Er ESRCH
103No thread could be found corresponding to that specified by the given
104thread ID.
105.It Bq Er ENOMEM
106There was not enough memory to allocate additional storage needed by the attributes
107object's implementation.
108.El
109.Sh SEE ALSO
110.Xr pthread_attr 3 ,
111.Xr pthread_attr_destroy 3 ,
112.Xr pthread_attr_getdetachstate 3 ,
113.Xr pthread_attr_getinheritsched 3 ,
114.Xr pthread_attr_getschedparam 3 ,
115.Xr pthread_attr_getschedpolicy 3 ,
116.Xr pthread_attr_getscope 3 ,
117.Xr pthread_attr_getstack 3 ,
118.Xr pthread_attr_getstackaddr 3 ,
119.Xr pthread_attr_getstacksize 3 ,
120.Xr pthread_attr_init 3 ,
121.Xr pthread_np 3
122.Sh AUTHORS
123The
124.Fn pthread_attr_get_np
125function and this manual page were written by
126.An Alexey Zelkin Aq Mt phantom@FreeBSD.org ,
127and the latter was revised by
128.An Olivier Certner Aq Mt olce@FreeBSD.org .
129