]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/pthread_getattr_default_np.3
fanotify_init.2, fanotify.7: Document FAN_REPORT_TID
[thirdparty/man-pages.git] / man3 / pthread_getattr_default_np.3
CommitLineData
0925dc68
MK
1.\" Copyright (c) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
2.\"
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.
7.\"
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.
12.\"
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
19.\" professionally.
20.\"
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\" %%%LICENSE_END
24.\"
4b8c67d9 25.TH PTHREAD_GETATTR_DEFAULT_NP 3 2017-09-15 "Linux" "Linux Programmer's Manual"
0925dc68
MK
26.SH NAME
27pthread_getattr_default_np, pthread_setattr_default_np, \-
28get or set default thread-creation attributes
29.SH SYNOPSIS
30.nf
31.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
32.B #include <pthread.h>
f90f031e 33.PP
0925dc68
MK
34.BI "int pthread_getattr_default_np(pthread_attr_t *" attr );
35.BI "int pthread_setattr_default_np(pthread_attr_t *" attr );
68e4db0a 36.PP
0925dc68
MK
37Compile and link with \fI\-pthread\fP.
38.fi
39.SH DESCRIPTION
40The
41.BR pthread_setattr_default_np ()
42function sets the default attributes used for creation of a new
43thread\(emthat is, the attributes that are used when
44.BR pthread_create (3)
45is called with a second argument that is NULL.
46The default attributes are set using the attributes supplied in
47.IR *attr ,
48a previously initialized thread attributes object.
49Note the following details about the supplied attributes object:
50.IP * 3
51The attribute settings in the object must be valid.
52.IP *
53The
54.IR "stack address"
55attribute must not be set in the object.
56.IP *
57Setting the
58.IR "stack size"
59attribute to zero means leave the default stack size unchanged.
60.PP
61The
62.BR pthread_getattr_default_np ()
63function initializes the thread attributes object referred to by
64.I attr
65so that it contains the default attributes used for thread creation.
66.SH ERRORS
67.TP
68.B EINVAL
69.RB ( pthread_setattr_default_np ())
70One of the attribute settings in
71.IR attr
72is invalid, or the stack address attribute is set in
73.IR attr .
74.TP
75.B ENOMEM
76.\" Can happen (but unlikely) while trying to allocate memory for cpuset
77.RB ( pthread_setattr_default_np ())
78Insufficient memory.
79.SH VERSIONS
80These functions are available in glibc since version 2.18.
81.SH ATTRIBUTES
82For an explanation of the terms used in this section, see
83.BR attributes (7).
84.ad l
85.TS
86allbox;
87lbw30 lb lb
88l l l.
89Interface Attribute Value
90T{
91.BR pthread_getattr_default_np (),
92.BR pthread_setattr_default_np ()
93T} Thread safety MT-Safe
94.TE
95.ad
96.SH CONFORMING TO
97These functions are nonstandard GNU extensions;
98hence the suffix "_np" (nonportable) in their names.
99.SH EXAMPLE
100The program below uses
101.BR pthread_getattr_default_np ()
102to fetch the default thread-creation attributes and then displays
103various settings from the returned thread attributes object.
104When running the program, we see the following output:
847e0d88 105.PP
0925dc68 106.in +4n
b8302363 107.EX
0925dc68
MK
108$ \fB./a.out\fP
109Stack size: 8388608
110Guard size: 4096
111Scheduling policy: SCHED_OTHER
112Scheduling priority: 0
113Detach state: JOINABLE
114Inherit scheduler: INHERIT
b8302363 115.EE
0925dc68 116.in
847e0d88 117.PP
0925dc68
MK
118.SS Program source
119\&
e7d0bb47 120.EX
0925dc68
MK
121#define _GNU_SOURCE
122#include <pthread.h>
123#include <stdio.h>
124#include <stdlib.h>
125#include <errno.h>
126
127#define errExitEN(en, msg) \\
128 do { errno = en; perror(msg); \\
129 exit(EXIT_FAILURE); } while (0)
130
131static void
132display_pthread_attr(pthread_attr_t *attr)
133{
134 int s;
135 size_t stacksize;
136 size_t guardsize;
137 int policy;
138 struct sched_param schedparam;
139 int detachstate;
140 int inheritsched;
141
142 s = pthread_attr_getstacksize(attr, &stacksize);
143 if (s != 0)
144 errExitEN(s, "pthread_attr_getstacksize");
145 printf("Stack size: %zd\\n", stacksize);
146
147 s = pthread_attr_getguardsize(attr, &guardsize);
148 if (s != 0)
149 errExitEN(s, "pthread_attr_getguardsize");
150 printf("Guard size: %zd\\n", guardsize);
151
152 s = pthread_attr_getschedpolicy(attr, &policy);
153 if (s != 0)
154 errExitEN(s, "pthread_attr_getschedpolicy");
1b9d5819 155 printf("Scheduling policy: %s\\n",
0925dc68
MK
156 (policy == SCHED_FIFO) ? "SCHED_FIFO" :
157 (policy == SCHED_RR) ? "SCHED_RR" :
158 (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
159
160 s = pthread_attr_getschedparam(attr, &schedparam);
161 if (s != 0)
162 errExitEN(s, "pthread_attr_getschedparam");
163 printf("Scheduling priority: %d\\n", schedparam.sched_priority);
164
165 s = pthread_attr_getdetachstate(attr, &detachstate);
166 if (s != 0)
167 errExitEN(s, "pthread_attr_getdetachstate");
168 printf("Detach state: %s\\n",
169 (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
170 (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
171 "???");
172
173 s = pthread_attr_getinheritsched(attr, &inheritsched);
174 if (s != 0)
175 errExitEN(s, "pthread_attr_getinheritsched");
176 printf("Inherit scheduler: %s\\n",
177 (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
178 (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
179 "???");
180}
181
182int
183main(int argc, char *argv[])
184{
185 int s;
186 pthread_attr_t attr;
187
188 s = pthread_getattr_default_np(&attr);
189 if (s != 0)
190 errExitEN(s, "pthread_getattr_default_np");
191
192 display_pthread_attr(&attr);
193
194 exit(EXIT_SUCCESS);
195}
e7d0bb47 196.EE
0925dc68
MK
197.SH SEE ALSO
198.ad l
199.nh
200.BR pthread_attr_getaffinity_np (3),
201.BR pthread_attr_getdetachstate (3),
202.BR pthread_attr_getguardsize (3),
203.BR pthread_attr_getinheritsched (3),
204.BR pthread_attr_getschedparam (3),
205.BR pthread_attr_getschedpolicy (3),
206.BR pthread_attr_getscope (3),
207.BR pthread_attr_getstack (3),
208.BR pthread_attr_getstackaddr (3),
209.BR pthread_attr_getstacksize (3),
210.BR pthread_attr_init (3),
211.BR pthread_create (3),
212.BR pthreads (7)