OSDN Git Service

LDP: Update draft based on the previous commit (pthread)
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / pthread_getattr_default_np.3
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 .\"
25 .\"*******************************************************************
26 .\"
27 .\" This file was generated with po4a. Translate the source file.
28 .\"
29 .\"*******************************************************************
30 .TH PTHREAD_GETATTR_DEFAULT_NP 3 2020\-06\-09 Linux "Linux Programmer's Manual"
31 .SH 名前
32 pthread_getattr_default_np, pthread_setattr_default_np, \- get or set default
33 thread\-creation attributes
34 .SH 書式
35 .nf
36 \fB#define _GNU_SOURCE\fP             /* See feature_test_macros(7) */
37 \fB#include <pthread.h>\fP
38 .PP
39 \fBint pthread_getattr_default_np(pthread_attr_t *\fP\fIattr\fP\fB);\fP
40 \fBint pthread_setattr_default_np(pthread_attr_t *\fP\fIattr\fP\fB);\fP
41 .PP
42 \fI\-pthread\fP でコンパイルしてリンクする。
43 .fi
44 .SH 説明
45 The \fBpthread_setattr_default_np\fP()  function sets the default attributes
46 used for creation of a new thread\(emthat is, the attributes that are used
47 when \fBpthread_create\fP(3)  is called with a second argument that is NULL.
48 The default attributes are set using the attributes supplied in \fI*attr\fP, a
49 previously initialized thread attributes object.  Note the following details
50 about the supplied attributes object:
51 .IP * 3
52 The attribute settings in the object must be valid.
53 .IP *
54 The \fIstack address\fP attribute must not be set in the object.
55 .IP *
56 Setting the \fIstack size\fP attribute to zero means leave the default stack
57 size unchanged.
58 .PP
59 The \fBpthread_getattr_default_np\fP()  function initializes the thread
60 attributes object referred to by \fIattr\fP so that it contains the default
61 attributes used for thread creation.
62 .SH エラー
63 .TP 
64 \fBEINVAL\fP
65 (\fBpthread_setattr_default_np\fP())  One of the attribute settings in \fIattr\fP
66 is invalid, or the stack address attribute is set in \fIattr\fP.
67 .TP 
68 \fBENOMEM\fP
69 .\" Can happen (but unlikely) while trying to allocate memory for cpuset
70 (\fBpthread_setattr_default_np\fP())  Insufficient memory.
71 .SH バージョン
72 これらの関数は glibc バージョン 2.18 以降で利用できる。
73 .SH 属性
74 この節で使用されている用語の説明については、 \fBattributes\fP(7) を参照。
75 .ad l
76 .TS
77 allbox;
78 lbw30 lb lb
79 l l l.
80 インターフェース        属性  値
81 T{
82 \fBpthread_getattr_default_np\fP(),
83 \fBpthread_setattr_default_np\fP()
84 T}      Thread safety   MT\-Safe
85 .TE
86 .ad
87 .SH 準拠
88 これらの関数は非標準の GNU による拡張である。そのため、名前に "_np" (nonportable; 移植性がない) という接尾辞が付いている。
89 .SH 例
90 The program below uses \fBpthread_getattr_default_np\fP()  to fetch the default
91 thread\-creation attributes and then displays various settings from the
92 returned thread attributes object.  When running the program, we see the
93 following output:
94 .PP
95 .in +4n
96 .EX
97 $ \fB./a.out\fP
98 Stack size:          8388608
99 Guard size:          4096
100 Scheduling policy:   SCHED_OTHER
101 Scheduling priority: 0
102 Detach state:        JOINABLE
103 Inherit scheduler:   INHERIT
104 .EE
105 .in
106 .SS プログラムのソース
107 \&
108 .EX
109 #define _GNU_SOURCE
110 #include <pthread.h>
111 #include <stdio.h>
112 #include <stdlib.h>
113 #include <errno.h>
114
115 #define errExitEN(en, msg) \e
116                         do { errno = en; perror(msg); \e
117                              exit(EXIT_FAILURE); } while (0)
118
119 static void
120 display_pthread_attr(pthread_attr_t *attr)
121 {
122     int s;
123     size_t stacksize;
124     size_t guardsize;
125     int policy;
126     struct sched_param schedparam;
127     int detachstate;
128     int inheritsched;
129
130     s = pthread_attr_getstacksize(attr, &stacksize);
131     if (s != 0)
132         errExitEN(s, "pthread_attr_getstacksize");
133     printf("Stack size:          %zd\en", stacksize);
134
135     s = pthread_attr_getguardsize(attr, &guardsize);
136     if (s != 0)
137         errExitEN(s, "pthread_attr_getguardsize");
138     printf("Guard size:          %zd\en", guardsize);
139
140     s = pthread_attr_getschedpolicy(attr, &policy);
141     if (s != 0)
142         errExitEN(s, "pthread_attr_getschedpolicy");
143     printf("Scheduling policy:   %s\en",
144             (policy == SCHED_FIFO) ? "SCHED_FIFO" :
145             (policy == SCHED_RR) ? "SCHED_RR" :
146             (policy == SCHED_OTHER) ? "SCHED_OTHER" : "[unknown]");
147
148     s = pthread_attr_getschedparam(attr, &schedparam);
149     if (s != 0)
150         errExitEN(s, "pthread_attr_getschedparam");
151     printf("Scheduling priority: %d\en", schedparam.sched_priority);
152
153     s = pthread_attr_getdetachstate(attr, &detachstate);
154     if (s != 0)
155         errExitEN(s, "pthread_attr_getdetachstate");
156     printf("Detach state:        %s\en",
157             (detachstate == PTHREAD_CREATE_DETACHED) ? "DETACHED" :
158             (detachstate == PTHREAD_CREATE_JOINABLE) ? "JOINABLE" :
159             "???");
160
161     s = pthread_attr_getinheritsched(attr, &inheritsched);
162     if (s != 0)
163         errExitEN(s, "pthread_attr_getinheritsched");
164     printf("Inherit scheduler:   %s\en",
165             (inheritsched == PTHREAD_INHERIT_SCHED) ? "INHERIT" :
166             (inheritsched == PTHREAD_EXPLICIT_SCHED) ? "EXPLICIT" :
167             "???");
168 }
169
170 int
171 main(int argc, char *argv[])
172 {
173     int s;
174     pthread_attr_t attr;
175
176     s = pthread_getattr_default_np(&attr);
177     if (s != 0)
178         errExitEN(s, "pthread_getattr_default_np");
179
180     display_pthread_attr(&attr);
181
182     exit(EXIT_SUCCESS);
183 }
184 .EE
185 .SH 関連項目
186 .ad l
187 .nh
188 \fBpthread_attr_getaffinity_np\fP(3), \fBpthread_attr_getdetachstate\fP(3),
189 \fBpthread_attr_getguardsize\fP(3), \fBpthread_attr_getinheritsched\fP(3),
190 \fBpthread_attr_getschedparam\fP(3), \fBpthread_attr_getschedpolicy\fP(3),
191 \fBpthread_attr_getscope\fP(3), \fBpthread_attr_getstack\fP(3),
192 \fBpthread_attr_getstackaddr\fP(3), \fBpthread_attr_getstacksize\fP(3),
193 \fBpthread_attr_init\fP(3), \fBpthread_create\fP(3), \fBpthreads\fP(7)
194 .SH この文書について
195 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
196 \%https://www.kernel.org/doc/man\-pages/ に書かれている。