2 .\" Copyright (c) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH pthread_getattr_default_np 3 (date) "Linux man-pages (unreleased)"
8 pthread_getattr_default_np, pthread_setattr_default_np, \-
9 get or set default thread-creation attributes
12 .RI ( libpthread ", " \-lpthread )
15 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
16 .B #include <pthread.h>
18 .BI "int pthread_getattr_default_np(pthread_attr_t *" attr );
19 .BI "int pthread_setattr_default_np(const pthread_attr_t *" attr );
23 .BR pthread_setattr_default_np ()
24 function sets the default attributes used for creation of a new
25 thread\[em]that is, the attributes that are used when
26 .BR pthread_create (3)
27 is called with a second argument that is NULL.
28 The default attributes are set using the attributes supplied in
30 a previously initialized thread attributes object.
31 Note the following details about the supplied attributes object:
33 The attribute settings in the object must be valid.
37 attribute must not be set in the object.
41 attribute to zero means leave the default stack size unchanged.
44 .BR pthread_getattr_default_np ()
45 function initializes the thread attributes object referred to by
47 so that it contains the default attributes used for thread creation.
51 .RB ( pthread_setattr_default_np ())
52 One of the attribute settings in
54 is invalid, or the stack address attribute is set in
58 .\" Can happen (but unlikely) while trying to allocate memory for cpuset
59 .RB ( pthread_setattr_default_np ())
62 For an explanation of the terms used in this section, see
68 Interface Attribute Value
72 .BR pthread_getattr_default_np (),
73 .BR pthread_setattr_default_np ()
74 T} Thread safety MT-Safe
78 hence the suffix "_np" (nonportable) in their names.
82 The program below uses
83 .BR pthread_getattr_default_np ()
84 to fetch the default thread-creation attributes and then displays
85 various settings from the returned thread attributes object.
86 When running the program, we see the following output:
93 Scheduling policy: SCHED_OTHER
94 Scheduling priority: 0
95 Detach state: JOINABLE
96 Inherit scheduler: INHERIT
101 .\" SRC BEGIN (pthread_getattr_default_np.c)
111 display_pthread_attr(pthread_attr_t *attr)
117 struct sched_param schedparam;
121 s = pthread_attr_getstacksize(attr, &stacksize);
123 errc(EXIT_FAILURE, s, "pthread_attr_getstacksize");
124 printf("Stack size: %zu\en", stacksize);
126 s = pthread_attr_getguardsize(attr, &guardsize);
128 errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
129 printf("Guard size: %zu\en", guardsize);
131 s = pthread_attr_getschedpolicy(attr, &policy);
133 errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
134 printf("Scheduling policy: %s\en",
135 (policy == SCHED_FIFO) ? "SCHED_FIFO" :
136 (policy == SCHED_RR) ? "SCHED_RR" :
137 (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
139 s = pthread_attr_getschedparam(attr, &schedparam);
141 errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
142 printf("Scheduling priority: %d\en", schedparam.sched_priority);
144 s = pthread_attr_getdetachstate(attr, &detachstate);
146 errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
147 printf("Detach state: %s\en",
148 (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
149 (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
152 s = pthread_attr_getinheritsched(attr, &inheritsched);
154 errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
155 printf("Inherit scheduler: %s\en",
156 (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
157 (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
167 s = pthread_getattr_default_np(&attr);
169 errc(EXIT_FAILURE, s, "pthread_getattr_default_np");
171 display_pthread_attr(&attr);
180 .BR pthread_attr_getaffinity_np (3),
181 .BR pthread_attr_getdetachstate (3),
182 .BR pthread_attr_getguardsize (3),
183 .BR pthread_attr_getinheritsched (3),
184 .BR pthread_attr_getschedparam (3),
185 .BR pthread_attr_getschedpolicy (3),
186 .BR pthread_attr_getscope (3),
187 .BR pthread_attr_getstack (3),
188 .BR pthread_attr_getstackaddr (3),
189 .BR pthread_attr_getstacksize (3),
190 .BR pthread_attr_init (3),
191 .BR pthread_create (3),