2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2016 Joyent, Inc.
15 .Dt PTHREAD_ATTR_GET_NP 3C
18 .Nm pthread_attr_get_np
19 .Nd get pthread attributes of a running thread
23 .Fo pthread_attr_get_np
24 .Fa "pthread_t thread"
25 .Fa "pthread_attr_t *attr"
29 .Fn pthread_attr_get_np
30 function provides a way to get the attributes of the thread
32 after it has been created.
33 This function is most commonly used to obtain the actual location and size of a
36 The attributes pointer,
38 will be filled in with the current attributes for the thread.
39 The attributes should be allocated by a call to
40 .Xr pthread_attr_init 3C
42 .Fn pthrad_attr_get_np
46 is done being used, it should be destroyed through a call to
47 .Xr pthread_attr_destroy 3C .
49 The attributes of the thread
51 will be the same as those passed in at the time
53 was called (or the default set if none were specified), except that the
54 following values will be updated:
56 .It Sy Thread Stack Size
57 If no explicit stack size was specified, then
59 will contain the actual size of the stack.
61 If the size of the stack was specified, then it may have been changed to
62 ensure that the required alignment of the platform is satisfied.
63 .It Sy The Stack Address
64 If no stack address was specified, then
66 will contain the actual address of the stack that the system allocated
68 .It Sy Thread Detach State
69 The detach state, whether or not the thread may be joined by a call to
71 may have changed since the process was created due to a call to
72 .Xr pthread_detach 3C .
74 will reflect the current setting of
76 .It Sy Thread Scheduling Parameter
77 The scheduling parameter attribute will be updated with the current
78 scheduling parameter of
80 This is the same information as available through
81 .Xr pthread_getschedparam 3C
82 and it is the preferred interface for obtaining that information.
83 .It Sy Thread Scheduling Policy
84 The scheduling policy attribute of
86 will be updated with the current scheduling policy being applied to the
88 This may have changed, for example, due to a call to
89 .Xr pthread_setschedparam 3C .
90 As with the thread's scheduling parameter, the preferred interface for
91 obtaining this information is by using
92 .Xr pthread_getschedparam 3C .
93 .It Sy Thread Guard Size
94 The value of the guard size attribute for the thread will be updated to
95 reflect the actual size of the guard installed for
97 For more information on the guard size of a thread and its purpose, see
98 .Xr pthread_attr_getguardsize 3C .
101 Upon successful completion, the
102 .Fn pthread_attr_get_np
104 .Fn pthread_getattr_np
107 Otherwise, an error number is returned to indicate the error.
109 The following program demonstrates how to use these functions to get
110 the location and stack size of a newly created thread.
119 static pthread_t g_thr;
122 print_stackinfo(void *arg)
126 pthread_t *thrp = arg;
130 if (pthread_attr_init(&attr) != 0) {
131 fprintf(stderr, "failed to init attr: %s\\n",
136 if (pthread_attr_get_np(*thrp, &attr) != 0) {
137 fprintf(stderr, "failed to get thread attributes: %s\\n",
142 ret = pthread_attr_getstackaddr(&attr, &stk);
144 ret = pthread_attr_getstacksize(&attr, &stksize);
146 (void) printf("stack base is at %p, it is %d bytes large\\n",
156 if ((ret = pthread_create(&g_thr, NULL, print_stackinfo,
158 fprintf(stderr, "failed to create a thread: %s\\n",
163 pthread_join(g_thr, NULL);
169 .Fn pthread_attr_get_np
170 function will fail if:
173 The pthread_attr_t object
175 was not properly initialized with a call to
176 .Xr pthread_attr_init 3C .
178 No thread could be found corresponding to the specified thread ID,
181 .Sh INTERFACE STABILITY
186 .Xr pthread_attr_destroy 3C ,
187 .Xr pthread_attr_getdetachstate 3C ,
188 .Xr pthread_attr_getguardsize 3C ,
189 .Xr pthread_attr_getinheritsched 3C ,
190 .Xr pthread_attr_getschedparam 3C ,
191 .Xr pthread_attr_getschedpolicy 3C ,
192 .Xr pthread_attr_getscope 3C ,
193 .Xr pthread_attr_getstackaddr 3C ,
194 .Xr pthread_attr_getstacksize 3C ,
195 .Xr pthread_attr_init 3C ,
196 .Xr pthread_create 3C ,
197 .Xr pthread_detach 3C ,
198 .Xr pthread_getschedparam 3C ,
199 .Xr pthread_setschedparam 3C ,