1 .\" Copyright (c) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PTHREAD_GETATTR_DEFAULT_NP 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 pthread_getattr_default_np, pthread_setattr_default_np, \-
28 get or set default thread-creation attributes
31 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
32 .B #include <pthread.h>
34 .BI "int pthread_getattr_default_np(pthread_attr_t *" attr );
35 .BI "int pthread_setattr_default_np(const pthread_attr_t *" attr );
37 Compile and link with \fI\-pthread\fP.
41 .BR pthread_setattr_default_np ()
42 function sets the default attributes used for creation of a new
43 thread\(emthat is, the attributes that are used when
44 .BR pthread_create (3)
45 is called with a second argument that is NULL.
46 The default attributes are set using the attributes supplied in
48 a previously initialized thread attributes object.
49 Note the following details about the supplied attributes object:
51 The attribute settings in the object must be valid.
55 attribute must not be set in the object.
59 attribute to zero means leave the default stack size unchanged.
62 .BR pthread_getattr_default_np ()
63 function initializes the thread attributes object referred to by
65 so that it contains the default attributes used for thread creation.
69 .RB ( pthread_setattr_default_np ())
70 One of the attribute settings in
72 is invalid, or the stack address attribute is set in
76 .\" Can happen (but unlikely) while trying to allocate memory for cpuset
77 .RB ( pthread_setattr_default_np ())
80 These functions are available in glibc since version 2.18.
82 For an explanation of the terms used in this section, see
90 Interface Attribute Value
92 .BR pthread_getattr_default_np (),
93 .BR pthread_setattr_default_np ()
94 T} Thread safety MT-Safe
100 These functions are nonstandard GNU extensions;
101 hence the suffix "_np" (nonportable) in their names.
103 The program below uses
104 .BR pthread_getattr_default_np ()
105 to fetch the default thread-creation attributes and then displays
106 various settings from the returned thread attributes object.
107 When running the program, we see the following output:
114 Scheduling policy: SCHED_OTHER
115 Scheduling priority: 0
116 Detach state: JOINABLE
117 Inherit scheduler: INHERIT
129 #define errExitEN(en, msg) \e
130 do { errno = en; perror(msg); \e
131 exit(EXIT_FAILURE); } while (0)
134 display_pthread_attr(pthread_attr_t *attr)
140 struct sched_param schedparam;
144 s = pthread_attr_getstacksize(attr, &stacksize);
146 errExitEN(s, "pthread_attr_getstacksize");
147 printf("Stack size: %zd\en", stacksize);
149 s = pthread_attr_getguardsize(attr, &guardsize);
151 errExitEN(s, "pthread_attr_getguardsize");
152 printf("Guard size: %zd\en", guardsize);
154 s = pthread_attr_getschedpolicy(attr, &policy);
156 errExitEN(s, "pthread_attr_getschedpolicy");
157 printf("Scheduling policy: %s\en",
158 (policy == SCHED_FIFO) ? "SCHED_FIFO" :
159 (policy == SCHED_RR) ? "SCHED_RR" :
160 (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
162 s = pthread_attr_getschedparam(attr, &schedparam);
164 errExitEN(s, "pthread_attr_getschedparam");
165 printf("Scheduling priority: %d\en", schedparam.sched_priority);
167 s = pthread_attr_getdetachstate(attr, &detachstate);
169 errExitEN(s, "pthread_attr_getdetachstate");
170 printf("Detach state: %s\en",
171 (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
172 (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
175 s = pthread_attr_getinheritsched(attr, &inheritsched);
177 errExitEN(s, "pthread_attr_getinheritsched");
178 printf("Inherit scheduler: %s\en",
179 (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
180 (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
185 main(int argc, char *argv[])
190 s = pthread_getattr_default_np(&attr);
192 errExitEN(s, "pthread_getattr_default_np");
194 display_pthread_attr(&attr);
202 .BR pthread_attr_getaffinity_np (3),
203 .BR pthread_attr_getdetachstate (3),
204 .BR pthread_attr_getguardsize (3),
205 .BR pthread_attr_getinheritsched (3),
206 .BR pthread_attr_getschedparam (3),
207 .BR pthread_attr_getschedpolicy (3),
208 .BR pthread_attr_getscope (3),
209 .BR pthread_attr_getstack (3),
210 .BR pthread_attr_getstackaddr (3),
211 .BR pthread_attr_getstacksize (3),
212 .BR pthread_attr_init (3),
213 .BR pthread_create (3),