summaryrefslogtreecommitdiffstats
path: root/upstream/opensuse-tumbleweed/man3/pthread_getattr_default_np.3
blob: c185c9616cd5eb5a4a22613b7b7fce6e22ab6a58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
'\" t
.\" Copyright (c) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH pthread_getattr_default_np 3 2024-05-02 "Linux man-pages (unreleased)"
.SH NAME
pthread_getattr_default_np, pthread_setattr_default_np, \-
get or set default thread-creation attributes
.SH LIBRARY
POSIX threads library
.RI ( libpthread ", " \-lpthread )
.SH SYNOPSIS
.nf
.BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
.B #include <pthread.h>
.P
.BI "int pthread_getattr_default_np(pthread_attr_t *" attr );
.BI "int pthread_setattr_default_np(const pthread_attr_t *" attr );
.fi
.SH DESCRIPTION
The
.BR pthread_setattr_default_np ()
function sets the default attributes used for creation of a new
thread\[em]that is, the attributes that are used when
.BR pthread_create (3)
is called with a second argument that is NULL.
The default attributes are set using the attributes supplied in
.IR *attr ,
a previously initialized thread attributes object.
Note the following details about the supplied attributes object:
.IP \[bu] 3
The attribute settings in the object must be valid.
.IP \[bu]
The
.I stack address
attribute must not be set in the object.
.IP \[bu]
Setting the
.I stack size
attribute to zero means leave the default stack size unchanged.
.P
The
.BR pthread_getattr_default_np ()
function initializes the thread attributes object referred to by
.I attr
so that it contains the default attributes used for thread creation.
.SH ERRORS
.TP
.B EINVAL
.RB ( pthread_setattr_default_np ())
One of the attribute settings in
.I attr
is invalid, or the stack address attribute is set in
.IR attr .
.TP
.B ENOMEM
.\" Can happen (but unlikely) while trying to allocate memory for cpuset
.RB ( pthread_setattr_default_np ())
Insufficient memory.
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.TS
allbox;
lbx lb lb
l l l.
Interface	Attribute	Value
T{
.na
.nh
.BR pthread_getattr_default_np (),
.BR pthread_setattr_default_np ()
T}	Thread safety	MT-Safe
.TE
.SH STANDARDS
GNU;
hence the suffix "_np" (nonportable) in their names.
.SH HISTORY
glibc 2.18.
.SH EXAMPLES
The program below uses
.BR pthread_getattr_default_np ()
to fetch the default thread-creation attributes and then displays
various settings from the returned thread attributes object.
When running the program, we see the following output:
.P
.in +4n
.EX
$ \fB./a.out\fP
Stack size:          8388608
Guard size:          4096
Scheduling policy:   SCHED_OTHER
Scheduling priority: 0
Detach state:        JOINABLE
Inherit scheduler:   INHERIT
.EE
.in
.SS Program source
\&
.\" SRC BEGIN (pthread_getattr_default_np.c)
.EX
#define _GNU_SOURCE
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
\&
static void
display_pthread_attr(pthread_attr_t *attr)
{
    int s;
    size_t stacksize;
    size_t guardsize;
    int policy;
    struct sched_param schedparam;
    int detachstate;
    int inheritsched;
\&
    s = pthread_attr_getstacksize(attr, &stacksize);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getstacksize");
    printf("Stack size:          %zu\en", stacksize);
\&
    s = pthread_attr_getguardsize(attr, &guardsize);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
    printf("Guard size:          %zu\en", guardsize);
\&
    s = pthread_attr_getschedpolicy(attr, &policy);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
    printf("Scheduling policy:   %s\en",
           (policy == SCHED_FIFO) ? "SCHED_FIFO" :
           (policy == SCHED_RR) ? "SCHED_RR" :
           (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
\&
    s = pthread_attr_getschedparam(attr, &schedparam);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
    printf("Scheduling priority: %d\en", schedparam.sched_priority);
\&
    s = pthread_attr_getdetachstate(attr, &detachstate);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
    printf("Detach state:        %s\en",
           (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
           (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
           "???");
\&
    s = pthread_attr_getinheritsched(attr, &inheritsched);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
    printf("Inherit scheduler:   %s\en",
           (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
           (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
           "???");
}
\&
int
main(void)
{
    int s;
    pthread_attr_t attr;
\&
    s = pthread_getattr_default_np(&attr);
    if (s != 0)
        errc(EXIT_FAILURE, s, "pthread_getattr_default_np");
\&
    display_pthread_attr(&attr);
\&
    exit(EXIT_SUCCESS);
}
.EE
.\" SRC END
.SH SEE ALSO
.ad l
.nh
.BR pthread_attr_getaffinity_np (3),
.BR pthread_attr_getdetachstate (3),
.BR pthread_attr_getguardsize (3),
.BR pthread_attr_getinheritsched (3),
.BR pthread_attr_getschedparam (3),
.BR pthread_attr_getschedpolicy (3),
.BR pthread_attr_getscope (3),
.BR pthread_attr_getstack (3),
.BR pthread_attr_getstackaddr (3),
.BR pthread_attr_getstacksize (3),
.BR pthread_attr_init (3),
.BR pthread_create (3),
.BR pthreads (7)