1 # SOME DESCRIPTIVE TITLE
2 # Copyright (C) YEAR Free Software Foundation, Inc.
3 # This file is distributed under the same license as the PACKAGE package.
4 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
9 "Project-Id-Version: PACKAGE VERSION\n"
10 "POT-Creation-Date: 2012-04-25 05:36+0900\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
16 "Content-Type: text/plain; charset=CHARSET\n"
17 "Content-Transfer-Encoding: 8bit\n"
20 #: build/C/man2/getcontext.2:23
26 #: build/C/man2/getcontext.2:23
32 #: build/C/man2/getcontext.2:23 build/C/man3/pthread_attr_init.3:24 build/C/man3/pthread_attr_setaffinity_np.3:24 build/C/man3/pthread_attr_setdetachstate.3:24 build/C/man3/pthread_attr_setguardsize.3:24 build/C/man3/pthread_attr_setinheritsched.3:24 build/C/man3/pthread_attr_setschedparam.3:24 build/C/man3/pthread_attr_setschedpolicy.3:24 build/C/man3/pthread_attr_setscope.3:24 build/C/man3/pthread_attr_setstack.3:24 build/C/man3/pthread_attr_setstackaddr.3:24 build/C/man3/pthread_attr_setstacksize.3:24 build/C/man3/pthread_cancel.3:24 build/C/man3/pthread_cleanup_push.3:24 build/C/man3/pthread_cleanup_push_defer_np.3:24 build/C/man3/pthread_create.3:24 build/C/man3/pthread_detach.3:24 build/C/man3/pthread_equal.3:24 build/C/man3/pthread_exit.3:24 build/C/man3/pthread_getattr_np.3:24 build/C/man3/pthread_getcpuclockid.3:24 build/C/man3/pthread_join.3:24 build/C/man3/pthread_kill.3:24 build/C/man3/pthread_kill_other_threads_np.3:24 build/C/man3/pthread_self.3:24 build/C/man3/pthread_setaffinity_np.3:24 build/C/man3/pthread_setcancelstate.3:24 build/C/man3/pthread_setconcurrency.3:23 build/C/man3/pthread_setschedparam.3:24 build/C/man3/pthread_setschedprio.3:24 build/C/man3/pthread_sigmask.3:24 build/C/man3/pthread_sigqueue.3:23 build/C/man3/pthread_testcancel.3:24 build/C/man3/pthread_tryjoin_np.3:24 build/C/man3/pthread_yield.3:23 build/C/man7/pthreads.7:24
38 #: build/C/man2/getcontext.2:23 build/C/man3/makecontext.3:25 build/C/man3/pthread_attr_init.3:24 build/C/man3/pthread_attr_setaffinity_np.3:24 build/C/man3/pthread_attr_setdetachstate.3:24 build/C/man3/pthread_attr_setguardsize.3:24 build/C/man3/pthread_attr_setinheritsched.3:24 build/C/man3/pthread_attr_setschedparam.3:24 build/C/man3/pthread_attr_setschedpolicy.3:24 build/C/man3/pthread_attr_setscope.3:24 build/C/man3/pthread_attr_setstack.3:24 build/C/man3/pthread_attr_setstackaddr.3:24 build/C/man3/pthread_attr_setstacksize.3:24 build/C/man3/pthread_cancel.3:24 build/C/man3/pthread_cleanup_push.3:24 build/C/man3/pthread_cleanup_push_defer_np.3:24 build/C/man3/pthread_create.3:24 build/C/man3/pthread_detach.3:24 build/C/man3/pthread_equal.3:24 build/C/man3/pthread_exit.3:24 build/C/man3/pthread_getattr_np.3:24 build/C/man3/pthread_getcpuclockid.3:24 build/C/man3/pthread_join.3:24 build/C/man3/pthread_kill.3:24 build/C/man3/pthread_kill_other_threads_np.3:24 build/C/man3/pthread_self.3:24 build/C/man3/pthread_setaffinity_np.3:24 build/C/man3/pthread_setcancelstate.3:24 build/C/man3/pthread_setconcurrency.3:23 build/C/man3/pthread_setschedparam.3:24 build/C/man3/pthread_setschedprio.3:24 build/C/man3/pthread_sigmask.3:24 build/C/man3/pthread_sigqueue.3:23 build/C/man3/pthread_testcancel.3:24 build/C/man3/pthread_tryjoin_np.3:24 build/C/man3/pthread_yield.3:23 build/C/man7/pthreads.7:24
40 msgid "Linux Programmer's Manual"
44 #: build/C/man2/getcontext.2:24 build/C/man3/makecontext.3:26 build/C/man3/pthread_attr_init.3:25 build/C/man3/pthread_attr_setaffinity_np.3:25 build/C/man3/pthread_attr_setdetachstate.3:25 build/C/man3/pthread_attr_setguardsize.3:25 build/C/man3/pthread_attr_setinheritsched.3:25 build/C/man3/pthread_attr_setschedparam.3:25 build/C/man3/pthread_attr_setschedpolicy.3:25 build/C/man3/pthread_attr_setscope.3:25 build/C/man3/pthread_attr_setstack.3:25 build/C/man3/pthread_attr_setstackaddr.3:25 build/C/man3/pthread_attr_setstacksize.3:25 build/C/man3/pthread_cancel.3:25 build/C/man3/pthread_cleanup_push.3:25 build/C/man3/pthread_cleanup_push_defer_np.3:25 build/C/man3/pthread_create.3:25 build/C/man3/pthread_detach.3:25 build/C/man3/pthread_equal.3:25 build/C/man3/pthread_exit.3:25 build/C/man3/pthread_getattr_np.3:25 build/C/man3/pthread_getcpuclockid.3:25 build/C/man3/pthread_join.3:25 build/C/man3/pthread_kill.3:25 build/C/man3/pthread_kill_other_threads_np.3:25 build/C/man3/pthread_self.3:25 build/C/man3/pthread_setaffinity_np.3:25 build/C/man3/pthread_setcancelstate.3:25 build/C/man3/pthread_setconcurrency.3:24 build/C/man3/pthread_setschedparam.3:25 build/C/man3/pthread_setschedprio.3:25 build/C/man3/pthread_sigmask.3:25 build/C/man3/pthread_sigqueue.3:24 build/C/man3/pthread_testcancel.3:25 build/C/man3/pthread_tryjoin_np.3:25 build/C/man3/pthread_yield.3:24 build/C/man7/pthreads.7:25
50 #: build/C/man2/getcontext.2:26
51 msgid "getcontext, setcontext - get or set the user context"
55 #: build/C/man2/getcontext.2:26 build/C/man3/makecontext.3:28 build/C/man3/pthread_attr_init.3:28 build/C/man3/pthread_attr_setaffinity_np.3:28 build/C/man3/pthread_attr_setdetachstate.3:28 build/C/man3/pthread_attr_setguardsize.3:28 build/C/man3/pthread_attr_setinheritsched.3:28 build/C/man3/pthread_attr_setschedparam.3:28 build/C/man3/pthread_attr_setschedpolicy.3:28 build/C/man3/pthread_attr_setscope.3:28 build/C/man3/pthread_attr_setstack.3:28 build/C/man3/pthread_attr_setstackaddr.3:28 build/C/man3/pthread_attr_setstacksize.3:28 build/C/man3/pthread_cancel.3:27 build/C/man3/pthread_cleanup_push.3:28 build/C/man3/pthread_cleanup_push_defer_np.3:28 build/C/man3/pthread_create.3:27 build/C/man3/pthread_detach.3:27 build/C/man3/pthread_equal.3:27 build/C/man3/pthread_exit.3:27 build/C/man3/pthread_getattr_np.3:27 build/C/man3/pthread_getcpuclockid.3:27 build/C/man3/pthread_join.3:27 build/C/man3/pthread_kill.3:27 build/C/man3/pthread_kill_other_threads_np.3:27 build/C/man3/pthread_self.3:27 build/C/man3/pthread_setaffinity_np.3:28 build/C/man3/pthread_setcancelstate.3:28 build/C/man3/pthread_setconcurrency.3:27 build/C/man3/pthread_setschedparam.3:28 build/C/man3/pthread_setschedprio.3:27 build/C/man3/pthread_sigmask.3:27 build/C/man3/pthread_sigqueue.3:26 build/C/man3/pthread_testcancel.3:27 build/C/man3/pthread_tryjoin_np.3:28 build/C/man3/pthread_yield.3:26
61 #: build/C/man2/getcontext.2:28 build/C/man3/makecontext.3:30
62 msgid "B<#include E<lt>ucontext.hE<gt>>"
66 #: build/C/man2/getcontext.2:30
67 msgid "B<int getcontext(ucontext_t *>I<ucp>B<);>"
71 #: build/C/man2/getcontext.2:32
72 msgid "B<int setcontext(const ucontext_t *>I<ucp>B<);>"
76 #: build/C/man2/getcontext.2:32 build/C/man3/makecontext.3:35 build/C/man3/pthread_attr_init.3:37 build/C/man3/pthread_attr_setaffinity_np.3:40 build/C/man3/pthread_attr_setdetachstate.3:39 build/C/man3/pthread_attr_setguardsize.3:39 build/C/man3/pthread_attr_setinheritsched.3:39 build/C/man3/pthread_attr_setschedparam.3:39 build/C/man3/pthread_attr_setschedpolicy.3:39 build/C/man3/pthread_attr_setscope.3:39 build/C/man3/pthread_attr_setstack.3:52 build/C/man3/pthread_attr_setstackaddr.3:39 build/C/man3/pthread_attr_setstacksize.3:39 build/C/man3/pthread_cancel.3:35 build/C/man3/pthread_cleanup_push.3:38 build/C/man3/pthread_cleanup_push_defer_np.3:38 build/C/man3/pthread_create.3:36 build/C/man3/pthread_detach.3:35 build/C/man3/pthread_equal.3:35 build/C/man3/pthread_exit.3:35 build/C/man3/pthread_getattr_np.3:36 build/C/man3/pthread_getcpuclockid.3:36 build/C/man3/pthread_join.3:35 build/C/man3/pthread_kill.3:35 build/C/man3/pthread_kill_other_threads_np.3:33 build/C/man3/pthread_self.3:35 build/C/man3/pthread_setaffinity_np.3:40 build/C/man3/pthread_setcancelstate.3:37 build/C/man3/pthread_setconcurrency.3:36 build/C/man3/pthread_setschedparam.3:39 build/C/man3/pthread_setschedprio.3:35 build/C/man3/pthread_sigmask.3:36 build/C/man3/pthread_sigqueue.3:43 build/C/man3/pthread_testcancel.3:35 build/C/man3/pthread_tryjoin_np.3:40 build/C/man3/pthread_yield.3:34 build/C/man7/pthreads.7:27
82 #: build/C/man2/getcontext.2:44
84 "In a System V-like environment, one has the two types I<mcontext_t> and "
85 "I<ucontext_t> defined in I<E<lt>ucontext.hE<gt>> and the four functions "
86 "B<getcontext>(), B<setcontext>(), B<makecontext>(3) and B<swapcontext>(3) "
87 "that allow user-level context switching between multiple threads of control "
92 #: build/C/man2/getcontext.2:48
94 "The I<mcontext_t> type is machine-dependent and opaque. The I<ucontext_t> "
95 "type is a structure that has at least the following fields:"
99 #: build/C/man2/getcontext.2:58
102 "typedef struct ucontext {\n"
103 " struct ucontext *uc_link;\n"
104 " sigset_t uc_sigmask;\n"
105 " stack_t uc_stack;\n"
106 " mcontext_t uc_mcontext;\n"
112 #: build/C/man2/getcontext.2:75
114 "with I<sigset_t> and I<stack_t> defined in I<E<lt>signal.hE<gt>>. Here "
115 "I<uc_link> points to the context that will be resumed when the current "
116 "context terminates (in case the current context was created using "
117 "B<makecontext>(3)), I<uc_sigmask> is the set of signals blocked in this "
118 "context (see B<sigprocmask>(2)), I<uc_stack> is the stack used by this "
119 "context (see B<sigaltstack>(2)), and I<uc_mcontext> is the machine-specific "
120 "representation of the saved context, that includes the calling thread's "
125 #: build/C/man2/getcontext.2:80
127 "The function B<getcontext>() initializes the structure pointed at by I<ucp> "
128 "to the currently active context."
132 #: build/C/man2/getcontext.2:92
134 "The function B<setcontext>() restores the user context pointed at by "
135 "I<ucp>. A successful call does not return. The context should have been "
136 "obtained by a call of B<getcontext>(), or B<makecontext>(3), or passed as "
137 "third argument to a signal handler."
141 #: build/C/man2/getcontext.2:96
143 "If the context was obtained by a call of B<getcontext>(), program execution "
144 "continues as if this call just returned."
148 #: build/C/man2/getcontext.2:107
150 "If the context was obtained by a call of B<makecontext>(3), program "
151 "execution continues by a call to the function I<func> specified as the "
152 "second argument of that call to B<makecontext>(3). When the function "
153 "I<func> returns, we continue with the I<uc_link> member of the structure "
154 "I<ucp> specified as the first argument of that call to B<makecontext>(3). "
155 "When this member is NULL, the thread exits."
159 #: build/C/man2/getcontext.2:114
161 "If the context was obtained by a call to a signal handler, then old standard "
162 "text says that \"program execution continues with the program instruction "
163 "following the instruction interrupted by the signal\". However, this "
164 "sentence was removed in SUSv2, and the present verdict is \"the result is "
169 #: build/C/man2/getcontext.2:114 build/C/man3/makecontext.3:81 build/C/man3/pthread_attr_init.3:66 build/C/man3/pthread_attr_setaffinity_np.3:74 build/C/man3/pthread_attr_setdetachstate.3:75 build/C/man3/pthread_attr_setguardsize.3:88 build/C/man3/pthread_attr_setinheritsched.3:82 build/C/man3/pthread_attr_setschedparam.3:72 build/C/man3/pthread_attr_setschedpolicy.3:70 build/C/man3/pthread_attr_setscope.3:89 build/C/man3/pthread_attr_setstack.3:83 build/C/man3/pthread_attr_setstackaddr.3:72 build/C/man3/pthread_attr_setstacksize.3:59 build/C/man3/pthread_cancel.3:107 build/C/man3/pthread_cleanup_push.3:117 build/C/man3/pthread_create.3:113 build/C/man3/pthread_detach.3:47 build/C/man3/pthread_equal.3:39 build/C/man3/pthread_exit.3:69 build/C/man3/pthread_getattr_np.3:71 build/C/man3/pthread_getcpuclockid.3:44 build/C/man3/pthread_join.3:68 build/C/man3/pthread_kill.3:50 build/C/man3/pthread_self.3:44 build/C/man3/pthread_setaffinity_np.3:75 build/C/man3/pthread_setcancelstate.3:90 build/C/man3/pthread_setconcurrency.3:54 build/C/man3/pthread_setschedparam.3:102 build/C/man3/pthread_setschedprio.3:51 build/C/man3/pthread_sigmask.3:47 build/C/man3/pthread_sigqueue.3:63 build/C/man3/pthread_testcancel.3:48 build/C/man3/pthread_tryjoin_np.3:83 build/C/man3/pthread_yield.3:41
175 #: build/C/man2/getcontext.2:122
177 "When successful, B<getcontext>() returns 0 and B<setcontext>() does not "
178 "return. On error, both return -1 and set I<errno> appropriately."
182 #: build/C/man2/getcontext.2:122 build/C/man3/makecontext.3:93 build/C/man3/pthread_attr_init.3:69 build/C/man3/pthread_attr_setaffinity_np.3:77 build/C/man3/pthread_attr_setdetachstate.3:78 build/C/man3/pthread_attr_setguardsize.3:91 build/C/man3/pthread_attr_setinheritsched.3:85 build/C/man3/pthread_attr_setschedparam.3:75 build/C/man3/pthread_attr_setschedpolicy.3:73 build/C/man3/pthread_attr_setscope.3:92 build/C/man3/pthread_attr_setstack.3:86 build/C/man3/pthread_attr_setstackaddr.3:75 build/C/man3/pthread_attr_setstacksize.3:62 build/C/man3/pthread_cancel.3:112 build/C/man3/pthread_cleanup_push.3:119 build/C/man3/pthread_create.3:120 build/C/man3/pthread_detach.3:52 build/C/man3/pthread_equal.3:43 build/C/man3/pthread_exit.3:71 build/C/man3/pthread_getattr_np.3:74 build/C/man3/pthread_getcpuclockid.3:47 build/C/man3/pthread_join.3:73 build/C/man3/pthread_kill.3:55 build/C/man3/pthread_self.3:46 build/C/man3/pthread_setaffinity_np.3:78 build/C/man3/pthread_setcancelstate.3:93 build/C/man3/pthread_setconcurrency.3:66 build/C/man3/pthread_setschedparam.3:110 build/C/man3/pthread_setschedprio.3:59 build/C/man3/pthread_sigmask.3:52 build/C/man3/pthread_sigqueue.3:68 build/C/man3/pthread_testcancel.3:52 build/C/man3/pthread_tryjoin_np.3:87 build/C/man3/pthread_yield.3:46
188 #: build/C/man2/getcontext.2:124
189 msgid "None defined."
193 #: build/C/man2/getcontext.2:124 build/C/man3/makecontext.3:102 build/C/man3/pthread_attr_init.3:77 build/C/man3/pthread_attr_setaffinity_np.3:106 build/C/man3/pthread_attr_setdetachstate.3:85 build/C/man3/pthread_attr_setguardsize.3:104 build/C/man3/pthread_attr_setinheritsched.3:99 build/C/man3/pthread_attr_setschedparam.3:87 build/C/man3/pthread_attr_setschedpolicy.3:87 build/C/man3/pthread_attr_setscope.3:105 build/C/man3/pthread_attr_setstack.3:110 build/C/man3/pthread_attr_setstackaddr.3:81 build/C/man3/pthread_attr_setstacksize.3:81 build/C/man3/pthread_cancel.3:120 build/C/man3/pthread_cleanup_push.3:123 build/C/man3/pthread_cleanup_push_defer_np.3:99 build/C/man3/pthread_create.3:144 build/C/man3/pthread_detach.3:62 build/C/man3/pthread_equal.3:45 build/C/man3/pthread_exit.3:73 build/C/man3/pthread_getattr_np.3:96 build/C/man3/pthread_getcpuclockid.3:63 build/C/man3/pthread_join.3:96 build/C/man3/pthread_kill.3:64 build/C/man3/pthread_kill_other_threads_np.3:45 build/C/man3/pthread_self.3:48 build/C/man3/pthread_setaffinity_np.3:119 build/C/man3/pthread_setcancelstate.3:111 build/C/man3/pthread_setconcurrency.3:81 build/C/man3/pthread_setschedparam.3:139 build/C/man3/pthread_setschedprio.3:81 build/C/man3/pthread_sigmask.3:55 build/C/man3/pthread_sigqueue.3:91 build/C/man3/pthread_testcancel.3:56 build/C/man3/pthread_tryjoin_np.3:110 build/C/man3/pthread_yield.3:50
195 msgid "CONFORMING TO"
199 #: build/C/man2/getcontext.2:130
201 "SUSv2, POSIX.1-2001. POSIX.1-2008 removes the specification of "
202 "B<getcontext>(), citing portability issues, and recommending that "
203 "applications be rewritten to use POSIX threads instead."
207 #: build/C/man2/getcontext.2:130 build/C/man3/makecontext.3:110 build/C/man3/pthread_attr_init.3:79 build/C/man3/pthread_attr_setaffinity_np.3:109 build/C/man3/pthread_attr_setdetachstate.3:87 build/C/man3/pthread_attr_setguardsize.3:106 build/C/man3/pthread_attr_setschedparam.3:89 build/C/man3/pthread_attr_setscope.3:107 build/C/man3/pthread_attr_setstack.3:112 build/C/man3/pthread_attr_setstackaddr.3:84 build/C/man3/pthread_attr_setstacksize.3:83 build/C/man3/pthread_cancel.3:122 build/C/man3/pthread_cleanup_push.3:125 build/C/man3/pthread_create.3:146 build/C/man3/pthread_detach.3:64 build/C/man3/pthread_equal.3:47 build/C/man3/pthread_exit.3:75 build/C/man3/pthread_getcpuclockid.3:65 build/C/man3/pthread_join.3:98 build/C/man3/pthread_kill.3:66 build/C/man3/pthread_kill_other_threads_np.3:48 build/C/man3/pthread_self.3:50 build/C/man3/pthread_setaffinity_np.3:122 build/C/man3/pthread_setcancelstate.3:113 build/C/man3/pthread_setconcurrency.3:83 build/C/man3/pthread_setschedparam.3:141 build/C/man3/pthread_setschedprio.3:83 build/C/man3/pthread_sigmask.3:57 build/C/man3/pthread_yield.3:56
213 #: build/C/man2/getcontext.2:147
215 "The earliest incarnation of this mechanism was the "
216 "B<setjmp>(3)/B<longjmp>(3) mechanism. Since that does not define the "
217 "handling of the signal context, the next stage was the "
218 "B<sigsetjmp>(3)/B<siglongjmp>(3) pair. The present mechanism gives much "
219 "more control. On the other hand, there is no easy way to detect whether a "
220 "return from B<getcontext>() is from the first call, or via a "
221 "B<setcontext>() call. The user has to invent her own bookkeeping device, "
222 "and a register variable won't do since registers are restored."
226 #: build/C/man2/getcontext.2:158
228 "When a signal occurs, the current user context is saved and a new context is "
229 "created by the kernel for the signal handler. Do not leave the handler "
230 "using B<longjmp>(3): it is undefined what would happen with contexts. Use "
231 "B<siglongjmp>(3) or B<setcontext>() instead."
235 #: build/C/man2/getcontext.2:158 build/C/man3/makecontext.3:217 build/C/man3/pthread_attr_init.3:295 build/C/man3/pthread_attr_setaffinity_np.3:116 build/C/man3/pthread_attr_setdetachstate.3:109 build/C/man3/pthread_attr_setguardsize.3:156 build/C/man3/pthread_attr_setinheritsched.3:120 build/C/man3/pthread_attr_setschedparam.3:96 build/C/man3/pthread_attr_setschedpolicy.3:92 build/C/man3/pthread_attr_setscope.3:118 build/C/man3/pthread_attr_setstack.3:154 build/C/man3/pthread_attr_setstackaddr.3:108 build/C/man3/pthread_attr_setstacksize.3:109 build/C/man3/pthread_cancel.3:221 build/C/man3/pthread_cleanup_push.3:309 build/C/man3/pthread_cleanup_push_defer_np.3:102 build/C/man3/pthread_create.3:367 build/C/man3/pthread_detach.3:95 build/C/man3/pthread_equal.3:54 build/C/man3/pthread_exit.3:103 build/C/man3/pthread_getattr_np.3:343 build/C/man3/pthread_getcpuclockid.3:167 build/C/man3/pthread_join.3:125 build/C/man3/pthread_kill.3:73 build/C/man3/pthread_kill_other_threads_np.3:64 build/C/man3/pthread_self.3:74 build/C/man3/pthread_setaffinity_np.3:204 build/C/man3/pthread_setcancelstate.3:175 build/C/man3/pthread_setconcurrency.3:98 build/C/man3/pthread_setschedparam.3:429 build/C/man3/pthread_setschedprio.3:89 build/C/man3/pthread_sigmask.3:133 build/C/man3/pthread_sigqueue.3:93 build/C/man3/pthread_testcancel.3:61 build/C/man3/pthread_tryjoin_np.3:133 build/C/man3/pthread_yield.3:59 build/C/man7/pthreads.7:893
241 #: build/C/man2/getcontext.2:164
243 "B<sigaction>(2), B<sigaltstack>(2), B<sigprocmask>(2), B<longjmp>(3), "
244 "B<makecontext>(3), B<sigsetjmp>(3)"
248 #: build/C/man3/makecontext.3:25
254 #: build/C/man3/makecontext.3:25
260 #: build/C/man3/makecontext.3:25
266 #: build/C/man3/makecontext.3:28
267 msgid "makecontext, swapcontext - manipulate user context"
271 #: build/C/man3/makecontext.3:33
273 "B<void makecontext(ucontext_t *>I<ucp>B<, void (*>I<func>B<)(),> B<int "
278 #: build/C/man3/makecontext.3:35
279 msgid "B<int swapcontext(ucontext_t *>I<oucp>B<, ucontext_t *>I<ucp>B<);>"
283 #: build/C/man3/makecontext.3:46
285 "In a System V-like environment, one has the type I<ucontext_t> defined in "
286 "I<E<lt>ucontext.hE<gt>> and the four functions B<getcontext>(2), "
287 "B<setcontext>(2), B<makecontext>() and B<swapcontext>() that allow "
288 "user-level context switching between multiple threads of control within a "
293 #: build/C/man3/makecontext.3:49
294 msgid "For the type and the first two functions, see B<getcontext>(2)."
298 #: build/C/man3/makecontext.3:61
300 "The B<makecontext>() function modifies the context pointed to by I<ucp> "
301 "(which was obtained from a call to B<getcontext>(2)). Before invoking "
302 "B<makecontext>(), the caller must allocate a new stack for this context and "
303 "assign its address to I<ucp-E<gt>uc_stack>, and define a successor context "
304 "and assign its address to I<ucp-E<gt>uc_link>."
308 #: build/C/man3/makecontext.3:75
310 "When this context is later activated (using B<setcontext>(2) or "
311 "B<swapcontext>()) the function I<func> is called, and passed the series of "
312 "integer (I<int>) arguments that follow I<argc>; the caller must specify the "
313 "number of these arguments in I<argc>. When this function returns, the "
314 "successor context is activated. If the successor context pointer is NULL, "
319 #: build/C/man3/makecontext.3:81
321 "The B<swapcontext>() function saves the current context in the structure "
322 "pointed to by I<oucp>, and then activates the context pointed to by I<ucp>."
326 #: build/C/man3/makecontext.3:93
328 "When successful, B<swapcontext>() does not return. (But we may return "
329 "later, in case I<oucp> is activated, in which case it looks like "
330 "B<swapcontext>() returns 0.) On error, B<swapcontext>() returns -1 and "
331 "sets I<errno> appropriately."
335 #: build/C/man3/makecontext.3:94 build/C/man3/pthread_attr_setaffinity_np.3:100 build/C/man3/pthread_getattr_np.3:75
341 #: build/C/man3/makecontext.3:97
342 msgid "Insufficient stack space left."
346 #: build/C/man3/makecontext.3:97 build/C/man3/pthread_attr_setaffinity_np.3:104 build/C/man3/pthread_attr_setguardsize.3:102 build/C/man3/pthread_attr_setstack.3:108 build/C/man3/pthread_attr_setstackaddr.3:79 build/C/man3/pthread_attr_setstacksize.3:79 build/C/man3/pthread_getattr_np.3:94 build/C/man3/pthread_getcpuclockid.3:61 build/C/man3/pthread_setaffinity_np.3:117 build/C/man3/pthread_setconcurrency.3:79 build/C/man3/pthread_setschedprio.3:79 build/C/man3/pthread_sigqueue.3:87 build/C/man3/pthread_tryjoin_np.3:108
352 #: build/C/man3/makecontext.3:102
354 "B<makecontext>() and B<swapcontext>() are provided in glibc since version "
359 #: build/C/man3/makecontext.3:110
361 "SUSv2, POSIX.1-2001. POSIX.1-2008 removes the specifications of "
362 "B<makecontext>() and B<swapcontext>(), citing portability issues, and "
363 "recommending that applications be rewritten to use POSIX threads instead."
367 #: build/C/man3/makecontext.3:118
369 "The interpretation of I<ucp-E<gt>uc_stack> is just as in B<sigaltstack>(2), "
370 "namely, this struct contains the start and length of a memory area to be "
371 "used as the stack, regardless of the direction of growth of the stack. "
372 "Thus, it is not necessary for the user program to worry about this "
377 #: build/C/man3/makecontext.3:134
379 "On architectures where I<int> and pointer types are the same size (e.g., "
380 "x86-32, where both types are 32 bits), you may be able to get away with "
381 "passing pointers as arguments to B<makecontext>() following I<argc>. "
382 "However, doing this is not guaranteed to be portable, is undefined according "
383 "to the standards, and won't work on architectures where pointers are larger "
384 "than I<int>s. Nevertheless, starting with version 2.8, glibc makes some "
385 "changes to B<makecontext>(), to permit this on some 64-bit architectures "
390 #: build/C/man3/makecontext.3:134 build/C/man3/pthread_attr_init.3:85 build/C/man3/pthread_attr_setdetachstate.3:106 build/C/man3/pthread_attr_setguardsize.3:153 build/C/man3/pthread_attr_setinheritsched.3:117 build/C/man3/pthread_attr_setschedparam.3:93 build/C/man3/pthread_attr_setschedpolicy.3:89 build/C/man3/pthread_attr_setstack.3:151 build/C/man3/pthread_attr_setstacksize.3:106 build/C/man3/pthread_cancel.3:130 build/C/man3/pthread_cleanup_push.3:149 build/C/man3/pthread_create.3:200 build/C/man3/pthread_detach.3:91 build/C/man3/pthread_getattr_np.3:99 build/C/man3/pthread_getcpuclockid.3:76 build/C/man3/pthread_join.3:122 build/C/man3/pthread_setaffinity_np.3:152 build/C/man3/pthread_setcancelstate.3:172 build/C/man3/pthread_setschedparam.3:147 build/C/man3/pthread_sigmask.3:59 build/C/man3/pthread_testcancel.3:58 build/C/man3/pthread_tryjoin_np.3:113
396 #: build/C/man3/makecontext.3:142
398 "The example program below demonstrates the use of B<getcontext>(2), "
399 "B<makecontext>(), and B<swapcontext>(). Running the program produces the "
404 #: build/C/man3/makecontext.3:154
408 "main: swapcontext(&uctx_main, &uctx_func2)\n"
410 "func2: swapcontext(&uctx_func2, &uctx_func1)\n"
412 "func1: swapcontext(&uctx_func1, &uctx_func2)\n"
419 #: build/C/man3/makecontext.3:156 build/C/man3/pthread_attr_init.3:146 build/C/man3/pthread_cancel.3:146 build/C/man3/pthread_cleanup_push.3:225 build/C/man3/pthread_create.3:239 build/C/man3/pthread_getattr_np.3:177 build/C/man3/pthread_getcpuclockid.3:93 build/C/man3/pthread_setschedparam.3:222 build/C/man3/pthread_sigmask.3:77
421 msgid "Program source"
425 #: build/C/man3/makecontext.3:162
428 "#include E<lt>ucontext.hE<gt>\n"
429 "#include E<lt>stdio.hE<gt>\n"
430 "#include E<lt>stdlib.hE<gt>\n"
434 #: build/C/man3/makecontext.3:164
436 msgid "static ucontext_t uctx_main, uctx_func1, uctx_func2;\n"
440 #: build/C/man3/makecontext.3:167
443 "#define handle_error(msg) \\e\n"
444 " do { perror(msg); exit(EXIT_FAILURE); } while (0)\n"
448 #: build/C/man3/makecontext.3:177
454 " printf(\"func1: started\\en\");\n"
455 " printf(\"func1: swapcontext(&uctx_func1, &uctx_func2)\\en\");\n"
456 " if (swapcontext(&uctx_func1, &uctx_func2) == -1)\n"
457 " handle_error(\"swapcontext\");\n"
458 " printf(\"func1: returning\\en\");\n"
463 #: build/C/man3/makecontext.3:187
469 " printf(\"func2: started\\en\");\n"
470 " printf(\"func2: swapcontext(&uctx_func2, &uctx_func1)\\en\");\n"
471 " if (swapcontext(&uctx_func2, &uctx_func1) == -1)\n"
472 " handle_error(\"swapcontext\");\n"
473 " printf(\"func2: returning\\en\");\n"
478 #: build/C/man3/makecontext.3:193
482 "main(int argc, char *argv[])\n"
484 " char func1_stack[16384];\n"
485 " char func2_stack[16384];\n"
489 #: build/C/man3/makecontext.3:200
492 " if (getcontext(&uctx_func1) == -1)\n"
493 " handle_error(\"getcontext\");\n"
494 " uctx_func1.uc_stack.ss_sp = func1_stack;\n"
495 " uctx_func1.uc_stack.ss_size = sizeof(func1_stack);\n"
496 " uctx_func1.uc_link = &uctx_main;\n"
497 " makecontext(&uctx_func1, func1, 0);\n"
501 #: build/C/man3/makecontext.3:208
504 " if (getcontext(&uctx_func2) == -1)\n"
505 " handle_error(\"getcontext\");\n"
506 " uctx_func2.uc_stack.ss_sp = func2_stack;\n"
507 " uctx_func2.uc_stack.ss_size = sizeof(func2_stack);\n"
508 " /* Successor context is f1(), unless argc E<gt> 1 */\n"
509 " uctx_func2.uc_link = (argc E<gt> 1) ? NULL : &uctx_func1;\n"
510 " makecontext(&uctx_func2, func2, 0);\n"
514 #: build/C/man3/makecontext.3:212
517 " printf(\"main: swapcontext(&uctx_main, &uctx_func2)\\en\");\n"
518 " if (swapcontext(&uctx_main, &uctx_func2) == -1)\n"
519 " handle_error(\"swapcontext\");\n"
523 #: build/C/man3/makecontext.3:216
526 " printf(\"main: exiting\\en\");\n"
527 " exit(EXIT_SUCCESS);\n"
532 #: build/C/man3/makecontext.3:222
534 "B<getcontext>(2), B<sigaction>(2), B<sigaltstack>(2), B<sigprocmask>(2), "
539 #: build/C/man3/pthread_attr_init.3:24
541 msgid "PTHREAD_ATTR_INIT"
545 #: build/C/man3/pthread_attr_init.3:24
551 #: build/C/man3/pthread_attr_init.3:28
553 "pthread_attr_init, pthread_attr_destroy - initialize and destroy thread "
558 #: build/C/man3/pthread_attr_init.3:31 build/C/man3/pthread_attr_setdetachstate.3:31 build/C/man3/pthread_attr_setguardsize.3:31 build/C/man3/pthread_attr_setinheritsched.3:31 build/C/man3/pthread_attr_setschedparam.3:31 build/C/man3/pthread_attr_setschedpolicy.3:31 build/C/man3/pthread_attr_setscope.3:31 build/C/man3/pthread_attr_setstack.3:31 build/C/man3/pthread_attr_setstackaddr.3:31 build/C/man3/pthread_attr_setstacksize.3:31 build/C/man3/pthread_cancel.3:30 build/C/man3/pthread_cleanup_push.3:31 build/C/man3/pthread_cleanup_push_defer_np.3:31 build/C/man3/pthread_create.3:30 build/C/man3/pthread_detach.3:30 build/C/man3/pthread_equal.3:30 build/C/man3/pthread_exit.3:30 build/C/man3/pthread_join.3:30 build/C/man3/pthread_kill_other_threads_np.3:30 build/C/man3/pthread_self.3:30 build/C/man3/pthread_setcancelstate.3:31 build/C/man3/pthread_setconcurrency.3:30 build/C/man3/pthread_setschedparam.3:31 build/C/man3/pthread_setschedprio.3:30 build/C/man3/pthread_sigqueue.3:29 build/C/man3/pthread_testcancel.3:30 build/C/man3/pthread_yield.3:29
560 msgid "B<#include E<lt>pthread.hE<gt>>\n"
564 #: build/C/man3/pthread_attr_init.3:34
567 "B<int pthread_attr_init(pthread_attr_t *>I<attr>B<);>\n"
568 "B<int pthread_attr_destroy(pthread_attr_t *>I<attr>B<);>\n"
572 #: build/C/man3/pthread_attr_init.3:36 build/C/man3/pthread_attr_setaffinity_np.3:39 build/C/man3/pthread_attr_setdetachstate.3:38 build/C/man3/pthread_attr_setguardsize.3:38 build/C/man3/pthread_attr_setinheritsched.3:38 build/C/man3/pthread_attr_setschedparam.3:38 build/C/man3/pthread_attr_setschedpolicy.3:38 build/C/man3/pthread_attr_setscope.3:38 build/C/man3/pthread_attr_setstack.3:38 build/C/man3/pthread_attr_setstackaddr.3:38 build/C/man3/pthread_attr_setstacksize.3:38 build/C/man3/pthread_cancel.3:34 build/C/man3/pthread_cleanup_push.3:37 build/C/man3/pthread_equal.3:34 build/C/man3/pthread_exit.3:34 build/C/man3/pthread_getattr_np.3:35 build/C/man3/pthread_getcpuclockid.3:35 build/C/man3/pthread_self.3:34 build/C/man3/pthread_setaffinity_np.3:39 build/C/man3/pthread_setcancelstate.3:36 build/C/man3/pthread_setconcurrency.3:35 build/C/man3/pthread_setschedparam.3:38 build/C/man3/pthread_setschedprio.3:34 build/C/man3/pthread_testcancel.3:34
574 msgid "Compile and link with I<-pthread>.\n"
578 #: build/C/man3/pthread_attr_init.3:48
580 "The B<pthread_attr_init>() function initializes the thread attributes "
581 "object pointed to by I<attr> with default attribute values. After this "
582 "call, individual attributes of the object can be set using various related "
583 "functions (listed under SEE ALSO), and then the object can be used in one or "
584 "more B<pthread_create>(3) calls that create threads."
588 #: build/C/man3/pthread_attr_init.3:53
590 "Calling B<pthread_attr_init>() on a thread attributes object that has "
591 "already been initialized results in undefined behavior."
595 #: build/C/man3/pthread_attr_init.3:60
597 "When a thread attributes object is no longer required, it should be "
598 "destroyed using the B<pthread_attr_destroy>() function. Destroying a "
599 "thread attributes object has no effect on threads that were created using "
604 #: build/C/man3/pthread_attr_init.3:66
606 "Once a thread attributes object has been destroyed, it can be reinitialized "
607 "using B<pthread_attr_init>(). Any other use of a destroyed thread "
608 "attributes object has undefined results."
612 #: build/C/man3/pthread_attr_init.3:69 build/C/man3/pthread_attr_setaffinity_np.3:77 build/C/man3/pthread_attr_setdetachstate.3:78 build/C/man3/pthread_attr_setguardsize.3:91 build/C/man3/pthread_attr_setinheritsched.3:85 build/C/man3/pthread_attr_setschedparam.3:75 build/C/man3/pthread_attr_setschedpolicy.3:73 build/C/man3/pthread_attr_setscope.3:92 build/C/man3/pthread_attr_setstack.3:86 build/C/man3/pthread_attr_setstackaddr.3:75 build/C/man3/pthread_attr_setstacksize.3:62 build/C/man3/pthread_setaffinity_np.3:78 build/C/man3/pthread_setcancelstate.3:93
614 "On success, these functions return 0; on error, they return a nonzero error "
619 #: build/C/man3/pthread_attr_init.3:77
621 "POSIX.1-2001 documents an B<ENOMEM> error for B<pthread_attr_init>(); on "
622 "Linux these functions always succeed (but portable and future-proof "
623 "applications should nevertheless handle a possible error return)."
627 #: build/C/man3/pthread_attr_init.3:79 build/C/man3/pthread_attr_setdetachstate.3:87 build/C/man3/pthread_attr_setguardsize.3:106 build/C/man3/pthread_attr_setinheritsched.3:101 build/C/man3/pthread_attr_setschedparam.3:89 build/C/man3/pthread_attr_setschedpolicy.3:89 build/C/man3/pthread_attr_setscope.3:107 build/C/man3/pthread_attr_setstack.3:112 build/C/man3/pthread_attr_setstacksize.3:83 build/C/man3/pthread_cancel.3:122 build/C/man3/pthread_cleanup_push.3:125 build/C/man3/pthread_create.3:146 build/C/man3/pthread_detach.3:64 build/C/man3/pthread_equal.3:47 build/C/man3/pthread_exit.3:75 build/C/man3/pthread_getcpuclockid.3:65 build/C/man3/pthread_join.3:98 build/C/man3/pthread_kill.3:66 build/C/man3/pthread_self.3:50 build/C/man3/pthread_setcancelstate.3:113 build/C/man3/pthread_setconcurrency.3:83 build/C/man3/pthread_setschedparam.3:141 build/C/man3/pthread_setschedprio.3:83 build/C/man3/pthread_sigmask.3:57 build/C/man3/pthread_testcancel.3:58
628 msgid "POSIX.1-2001."
632 #: build/C/man3/pthread_attr_init.3:85
634 "The I<pthread_attr_t> type should be treated as opaque: any access to the "
635 "object other than via pthreads functions is nonportable and produces "
640 #: build/C/man3/pthread_attr_init.3:94
642 "The program below optionally makes use of B<pthread_attr_init>() and "
643 "various related functions to initialize a thread attributes object that is "
644 "used to create a single thread. Once created, the thread uses the "
645 "B<pthread_getattr_np>(3) function (a nonstandard GNU extension) to retrieve "
646 "the thread's attributes, and then displays those attributes."
650 #: build/C/man3/pthread_attr_init.3:103
652 "If the program is run with no command-line argument, then it passes NULL as "
653 "the I<attr> argument of B<pthread_create>(3), so that the thread is created "
654 "with default attributes. Running the program on Linux/x86-32 with the NPTL "
655 "threading implementation, we see the following:"
658 #. Results from glibc 2.8, SUSE 11.0; Oct 2008
660 #: build/C/man3/pthread_attr_init.3:119
663 "$B< ulimit -s> # No stack imit ==E<gt> default stack size is 2MB\n"
666 "Thread attributes:\n"
667 " Detach state = PTHREAD_CREATE_JOINABLE\n"
668 " Scope = PTHREAD_SCOPE_SYSTEM\n"
669 " Inherit scheduler = PTHREAD_INHERIT_SCHED\n"
670 " Scheduling policy = SCHED_OTHER\n"
671 " Scheduling priority = 0\n"
672 " Guard size = 4096 bytes\n"
673 " Stack address = 0x40196000\n"
674 " Stack size = 0x201000 bytes\n"
678 #: build/C/man3/pthread_attr_init.3:129
680 "When we supply a stack size as a command-line argument, the program "
681 "initializes a thread attributes object, sets various attributes in that "
682 "object, and passes a pointer to the object in the call to "
683 "B<pthread_create>(3). Running the program on Linux/x86-32 with the NPTL "
684 "threading implementation, we see the following:"
687 #. Results from glibc 2.8, SUSE 11.0; Oct 2008
689 #: build/C/man3/pthread_attr_init.3:144
692 "$B< ./a.out 0x3000000>\n"
693 "posix_memalign() allocated at 0x40197000\n"
694 "Thread attributes:\n"
695 " Detach state = PTHREAD_CREATE_DETACHED\n"
696 " Scope = PTHREAD_SCOPE_SYSTEM\n"
697 " Inherit scheduler = PTHREAD_EXPLICIT_SCHED\n"
698 " Scheduling policy = SCHED_OTHER\n"
699 " Scheduling priority = 0\n"
700 " Guard size = 0 bytes\n"
701 " Stack address = 0x40197000\n"
702 " Stack size = 0x3000000 bytes\n"
706 #: build/C/man3/pthread_attr_init.3:155 build/C/man3/pthread_getattr_np.3:186
709 "#define _GNU_SOURCE /* To get pthread_getattr_np() declaration */\n"
710 "#include E<lt>pthread.hE<gt>\n"
711 "#include E<lt>stdio.hE<gt>\n"
712 "#include E<lt>stdlib.hE<gt>\n"
713 "#include E<lt>unistd.hE<gt>\n"
714 "#include E<lt>errno.hE<gt>\n"
718 #: build/C/man3/pthread_attr_init.3:158 build/C/man3/pthread_cancel.3:157 build/C/man3/pthread_cleanup_push.3:237 build/C/man3/pthread_create.3:252 build/C/man3/pthread_getattr_np.3:189 build/C/man3/pthread_getcpuclockid.3:111 build/C/man3/pthread_setaffinity_np.3:170 build/C/man3/pthread_setschedparam.3:235 build/C/man3/pthread_sigmask.3:91
721 "#define handle_error_en(en, msg) \\e\n"
722 " do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)\n"
726 #: build/C/man3/pthread_attr_init.3:166
730 "display_pthread_attr(pthread_attr_t *attr, char *prefix)\n"
735 " struct sched_param sp;\n"
739 #: build/C/man3/pthread_attr_init.3:174
742 " s = pthread_attr_getdetachstate(attr, &i);\n"
744 " handle_error_en(s, \"pthread_attr_getdetachstate\");\n"
745 " printf(\"%sDetach state = %s\\en\", prefix,\n"
746 " (i == PTHREAD_CREATE_DETACHED) ? \"PTHREAD_CREATE_DETACHED\" :\n"
747 " (i == PTHREAD_CREATE_JOINABLE) ? \"PTHREAD_CREATE_JOINABLE\" :\n"
752 #: build/C/man3/pthread_attr_init.3:182
755 " s = pthread_attr_getscope(attr, &i);\n"
757 " handle_error_en(s, \"pthread_attr_getscope\");\n"
758 " printf(\"%sScope = %s\\en\", prefix,\n"
759 " (i == PTHREAD_SCOPE_SYSTEM) ? \"PTHREAD_SCOPE_SYSTEM\" :\n"
760 " (i == PTHREAD_SCOPE_PROCESS) ? \"PTHREAD_SCOPE_PROCESS\" :\n"
765 #: build/C/man3/pthread_attr_init.3:190
768 " s = pthread_attr_getinheritsched(attr, &i);\n"
770 " handle_error_en(s, \"pthread_attr_getinheritsched\");\n"
771 " printf(\"%sInherit scheduler = %s\\en\", prefix,\n"
772 " (i == PTHREAD_INHERIT_SCHED) ? \"PTHREAD_INHERIT_SCHED\" :\n"
773 " (i == PTHREAD_EXPLICIT_SCHED) ? \"PTHREAD_EXPLICIT_SCHED\" :\n"
778 #: build/C/man3/pthread_attr_init.3:199
781 " s = pthread_attr_getschedpolicy(attr, &i);\n"
783 " handle_error_en(s, \"pthread_attr_getschedpolicy\");\n"
784 " printf(\"%sScheduling policy = %s\\en\", prefix,\n"
785 " (i == SCHED_OTHER) ? \"SCHED_OTHER\" :\n"
786 " (i == SCHED_FIFO) ? \"SCHED_FIFO\" :\n"
787 " (i == SCHED_RR) ? \"SCHED_RR\" :\n"
792 #: build/C/man3/pthread_attr_init.3:204
795 " s = pthread_attr_getschedparam(attr, &sp);\n"
797 " handle_error_en(s, \"pthread_attr_getschedparam\");\n"
798 " printf(\"%sScheduling priority = %d\\en\", prefix, sp.sched_priority);\n"
802 #: build/C/man3/pthread_attr_init.3:209
805 " s = pthread_attr_getguardsize(attr, &v);\n"
807 " handle_error_en(s, \"pthread_attr_getguardsize\");\n"
808 " printf(\"%sGuard size = %d bytes\\en\", prefix, v);\n"
812 #: build/C/man3/pthread_attr_init.3:216
815 " s = pthread_attr_getstack(attr, &stkaddr, &v);\n"
817 " handle_error_en(s, \"pthread_attr_getstack\");\n"
818 " printf(\"%sStack address = %p\\en\", prefix, stkaddr);\n"
819 " printf(\"%sStack size = 0x%x bytes\\en\", prefix, v);\n"
824 #: build/C/man3/pthread_attr_init.3:222
828 "thread_start(void *arg)\n"
831 " pthread_attr_t gattr;\n"
835 #: build/C/man3/pthread_attr_init.3:226
838 " /* pthread_getattr_np() is a non-standard GNU extension that\n"
839 " retrieves the attributes of the thread specified in its\n"
840 " first argument */\n"
844 #: build/C/man3/pthread_attr_init.3:230
847 " s = pthread_getattr_np(pthread_self(), &gattr);\n"
849 " handle_error_en(s, \"pthread_getattr_np\");\n"
853 #: build/C/man3/pthread_attr_init.3:233
856 " printf(\"Thread attributes:\\en\");\n"
857 " display_pthread_attr(&gattr, \"\\et\");\n"
861 #: build/C/man3/pthread_attr_init.3:236 build/C/man3/pthread_getattr_np.3:238
864 " exit(EXIT_SUCCESS); /* Terminate all threads */\n"
869 #: build/C/man3/pthread_attr_init.3:244
873 "main(int argc, char *argv[])\n"
876 " pthread_attr_t attr;\n"
877 " pthread_attr_t *attrp; /* NULL or &attr */\n"
882 #: build/C/man3/pthread_attr_init.3:246 build/C/man3/pthread_setschedparam.3:353
884 msgid " attrp = NULL;\n"
888 #: build/C/man3/pthread_attr_init.3:250
891 " /* If a command-line argument was supplied, use it to set the\n"
892 " stack-size attribute and set a few other thread attributes,\n"
893 " and set attrp pointing to thread attributes object */\n"
897 #: build/C/man3/pthread_attr_init.3:254
900 " if (argc E<gt> 1) {\n"
906 #: build/C/man3/pthread_attr_init.3:256
908 msgid " attrp = &attr;\n"
912 #: build/C/man3/pthread_attr_init.3:260
915 " s = pthread_attr_init(&attr);\n"
917 " handle_error_en(s, \"pthread_attr_init\");\n"
921 #: build/C/man3/pthread_attr_init.3:264
924 " s = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);\n"
926 " handle_error_en(s, \"pthread_attr_setdetachstate\");\n"
930 #: build/C/man3/pthread_attr_init.3:268
933 " s = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);\n"
935 " handle_error_en(s, \"pthread_attr_setinheritsched\");\n"
939 #: build/C/man3/pthread_attr_init.3:270
941 msgid " stack_size = strtoul(argv[1], NULL, 0);\n"
945 #: build/C/man3/pthread_attr_init.3:274
948 " s = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stack_size);\n"
950 " handle_error_en(s, \"posix_memalign\");\n"
954 #: build/C/man3/pthread_attr_init.3:276
956 msgid " printf(\"posix_memalign() allocated at %p\\en\", sp);\n"
960 #: build/C/man3/pthread_attr_init.3:281
963 " s = pthread_attr_setstack(&attr, sp, stack_size);\n"
965 " handle_error_en(s, \"pthread_attr_setstack\");\n"
970 #: build/C/man3/pthread_attr_init.3:285 build/C/man3/pthread_getattr_np.3:333
973 " s = pthread_create(&thr, attrp, &thread_start, NULL);\n"
975 " handle_error_en(s, \"pthread_create\");\n"
979 #: build/C/man3/pthread_attr_init.3:291 build/C/man3/pthread_getattr_np.3:339
982 " if (attrp != NULL) {\n"
983 " s = pthread_attr_destroy(attrp);\n"
985 " handle_error_en(s, \"pthread_attr_destroy\");\n"
990 #: build/C/man3/pthread_attr_init.3:294 build/C/man3/pthread_getattr_np.3:342
993 " pause(); /* Terminates when other thread calls exit() */\n"
998 #: build/C/man3/pthread_attr_init.3:308
1000 "B<pthread_attr_setaffinity_np>(3), B<pthread_attr_setdetachstate>(3), "
1001 "B<pthread_attr_setguardsize>(3), B<pthread_attr_setinheritsched>(3), "
1002 "B<pthread_attr_setschedparam>(3), B<pthread_attr_setschedpolicy>(3), "
1003 "B<pthread_attr_setscope>(3), B<pthread_attr_setstack>(3), "
1004 "B<pthread_attr_setstackaddr>(3), B<pthread_attr_setstacksize>(3), "
1005 "B<pthread_create>(3), B<pthread_getattr_np>(3), B<pthreads>(7)"
1009 #: build/C/man3/pthread_attr_setaffinity_np.3:24
1011 msgid "PTHREAD_ATTR_SETAFFINITY_NP"
1015 #: build/C/man3/pthread_attr_setaffinity_np.3:24 build/C/man3/pthread_getattr_np.3:24 build/C/man3/pthread_setaffinity_np.3:24 build/C/man3/pthread_tryjoin_np.3:24
1021 #: build/C/man3/pthread_attr_setaffinity_np.3:28
1023 "pthread_attr_setaffinity_np, pthread_attr_getaffinity_np - set/get CPU "
1024 "affinity attribute in thread attributes object"
1028 #: build/C/man3/pthread_attr_setaffinity_np.3:32 build/C/man3/pthread_getattr_np.3:31 build/C/man3/pthread_setaffinity_np.3:32 build/C/man3/pthread_tryjoin_np.3:32
1031 "B<#define _GNU_SOURCE> /* See feature_test_macros(7) */\n"
1032 "B<#include E<lt>pthread.hE<gt>>\n"
1036 #: build/C/man3/pthread_attr_setaffinity_np.3:37
1039 "B<int pthread_attr_setaffinity_np(pthread_attr_t *>I<attr>B<,>\n"
1040 "B< size_t >I<cpusetsize>B<, const cpu_set_t "
1041 "*>I<cpuset>B<);>\n"
1042 "B<int pthread_attr_getaffinity_np(pthread_attr_t *>I<attr>B<,>\n"
1043 "B< size_t >I<cpusetsize>B<, cpu_set_t *>I<cpuset>B<);>\n"
1047 #: build/C/man3/pthread_attr_setaffinity_np.3:52
1049 "The B<pthread_attr_setaffinity_np>() function sets the CPU affinity mask "
1050 "attribute of the thread attributes object referred to by I<attr> to the "
1051 "value specified in I<cpuset>. This attribute determines the CPU affinity "
1052 "mask of a thread created using the thread attributes object I<attr>."
1056 #: build/C/man3/pthread_attr_setaffinity_np.3:61
1058 "The B<pthread_attr_getaffinity_np>() function returns the CPU affinity mask "
1059 "attribute of the thread attributes object referred to by I<attr> in the "
1060 "buffer pointed to by I<cpuset>."
1064 #: build/C/man3/pthread_attr_setaffinity_np.3:68
1066 "The argument I<cpusetsize> is the length (in bytes) of the buffer pointed to "
1067 "by I<cpuset>. Typically, this argument would be specified as "
1068 "I<sizeof(cpu_set_t)>."
1072 #: build/C/man3/pthread_attr_setaffinity_np.3:74 build/C/man3/pthread_setaffinity_np.3:65
1074 "For more details on CPU affinity masks, see B<sched_setaffinity>(2). For a "
1075 "description of a set of macros that can be used to manipulate and inspect "
1076 "CPU sets, see B<CPU_SET>(3)."
1080 #: build/C/man3/pthread_attr_setaffinity_np.3:78 build/C/man3/pthread_attr_setaffinity_np.3:90 build/C/man3/pthread_attr_setdetachstate.3:81 build/C/man3/pthread_attr_setinheritsched.3:88 build/C/man3/pthread_attr_setschedpolicy.3:76 build/C/man3/pthread_attr_setscope.3:95 build/C/man3/pthread_attr_setstack.3:89 build/C/man3/pthread_attr_setstacksize.3:65 build/C/man3/pthread_create.3:135 build/C/man3/pthread_detach.3:53 build/C/man3/pthread_join.3:83 build/C/man3/pthread_join.3:87 build/C/man3/pthread_kill.3:56 build/C/man3/pthread_setaffinity_np.3:82 build/C/man3/pthread_setaffinity_np.3:91 build/C/man3/pthread_setaffinity_np.3:107 build/C/man3/pthread_setcancelstate.3:97 build/C/man3/pthread_setcancelstate.3:105 build/C/man3/pthread_setconcurrency.3:69 build/C/man3/pthread_setschedparam.3:120 build/C/man3/pthread_setschedprio.3:60 build/C/man3/pthread_sigqueue.3:75
1086 #. The raw sched_getaffinity() system call returns the size (in bytes)
1087 #. of the cpumask_t type.
1089 #: build/C/man3/pthread_attr_setaffinity_np.3:90
1091 "(B<pthread_attr_setaffinity_np>()) I<cpuset> specified a CPU that was "
1092 "outside the set supported by the kernel. (The kernel configuration option "
1093 "B<CONFIG_NR_CPUS> defines the range of the set supported by the kernel data "
1094 "type used to represent CPU sets.)"
1098 #: build/C/man3/pthread_attr_setaffinity_np.3:100
1100 "(B<pthread_attr_getaffinity_np>()) A CPU in the affinity mask of the thread "
1101 "attributes object referred to by I<attr> lies outside the range specified by "
1102 "I<cpusetsize> (i.e., I<cpuset>/I<cpusetsize> is too small)."
1106 #: build/C/man3/pthread_attr_setaffinity_np.3:104
1107 msgid "(B<pthread_attr_setaffinity_np>()) Could not allocate memory."
1111 #: build/C/man3/pthread_attr_setaffinity_np.3:106 build/C/man3/pthread_setaffinity_np.3:119
1112 msgid "These functions are provided by glibc since version 2.3.4."
1116 #: build/C/man3/pthread_attr_setaffinity_np.3:109 build/C/man3/pthread_cleanup_push_defer_np.3:102 build/C/man3/pthread_setaffinity_np.3:122 build/C/man3/pthread_tryjoin_np.3:113
1118 "These functions are nonstandard GNU extensions; hence the suffix \"_np\" "
1119 "(nonportable) in the names."
1123 #: build/C/man3/pthread_attr_setaffinity_np.3:116 build/C/man3/pthread_setaffinity_np.3:148
1125 "In glibc 2.3.3 only, versions of these functions were provided that did not "
1126 "have a I<cpusetsize> argument. Instead the CPU set size given to the "
1127 "underlying system calls was always I<sizeof(cpu_set_t)>."
1131 #: build/C/man3/pthread_attr_setaffinity_np.3:121
1133 "B<sched_setaffinity>(2), B<pthread_attr_init>(3), "
1134 "B<pthread_setaffinity_np>(3), B<cpuset>(7), B<pthreads>(7)"
1138 #: build/C/man3/pthread_attr_setdetachstate.3:24
1140 msgid "PTHREAD_ATTR_SETDETACHSTATE"
1144 #: build/C/man3/pthread_attr_setdetachstate.3:24 build/C/man3/pthread_attr_setschedpolicy.3:24
1150 #: build/C/man3/pthread_attr_setdetachstate.3:28
1152 "pthread_attr_setdetachstate, pthread_attr_getdetachstate - set/get detach "
1153 "state attribute in thread attributes object"
1157 #: build/C/man3/pthread_attr_setdetachstate.3:36
1160 "B<int pthread_attr_setdetachstate(pthread_attr_t *>I<attr>B<, int "
1161 ">I<detachstate>B<);>\n"
1162 "B<int pthread_attr_getdetachstate(pthread_attr_t *>I<attr>B<, int "
1163 "*>I<detachstate>B<);>\n"
1167 #: build/C/man3/pthread_attr_setdetachstate.3:51
1169 "The B<pthread_attr_setdetachstate>() function sets the detach state "
1170 "attribute of the thread attributes object referred to by I<attr> to the "
1171 "value specified in I<detachstate>. The detach state attribute determines "
1172 "whether a thread created using the thread attributes object I<attr> will be "
1173 "created in a joinable or a detached state."
1177 #: build/C/man3/pthread_attr_setdetachstate.3:54
1178 msgid "The following values may be specified in I<detachstate>:"
1182 #: build/C/man3/pthread_attr_setdetachstate.3:54
1184 msgid "B<PTHREAD_CREATE_DETACHED>"
1188 #: build/C/man3/pthread_attr_setdetachstate.3:59
1189 msgid "Threads that are created using I<attr> will be created in a detached state."
1193 #: build/C/man3/pthread_attr_setdetachstate.3:59
1195 msgid "B<PTHREAD_CREATE_JOINABLE>"
1199 #: build/C/man3/pthread_attr_setdetachstate.3:64
1200 msgid "Threads that are created using I<attr> will be created in a joinable state."
1204 #: build/C/man3/pthread_attr_setdetachstate.3:68
1206 "The default setting of the detach state attribute in a newly initialized "
1207 "thread attributes object is B<PTHREAD_CREATE_JOINABLE>."
1211 #: build/C/man3/pthread_attr_setdetachstate.3:75
1213 "The B<pthread_attr_getdetachstate>() returns the detach state attribute of "
1214 "the thread attributes object I<attr> in the buffer pointed to by "
1219 #: build/C/man3/pthread_attr_setdetachstate.3:81
1220 msgid "B<pthread_attr_setdetachstate>() can fail with the following error:"
1224 #: build/C/man3/pthread_attr_setdetachstate.3:85
1225 msgid "An invalid value was specified in I<detachstate>."
1229 #: build/C/man3/pthread_attr_setdetachstate.3:91
1230 msgid "See B<pthread_create>(3) for more details on detached and joinable threads."
1234 #: build/C/man3/pthread_attr_setdetachstate.3:99
1236 "A thread that is created in a joinable state should eventually either be "
1237 "joined using B<pthread_join>(3) or detached using B<pthread_detach>(3); see "
1238 "B<pthread_create>(3)."
1242 #: build/C/man3/pthread_attr_setdetachstate.3:106
1244 "It is an error to specify the thread ID of a thread that was created in a "
1245 "detached state in a later call to B<pthread_detach>(3) or "
1246 "B<pthread_join>(3)."
1250 #: build/C/man3/pthread_attr_setdetachstate.3:109 build/C/man3/pthread_attr_setstack.3:154
1251 msgid "See B<pthread_attr_init>(3)."
1255 #: build/C/man3/pthread_attr_setdetachstate.3:114
1257 "B<pthread_attr_init>(3), B<pthread_create>(3), B<pthread_detach>(3), "
1258 "B<pthread_join>(3), B<pthreads>(7)"
1262 #: build/C/man3/pthread_attr_setguardsize.3:24
1264 msgid "PTHREAD_ATTR_SETGUARDSIZE"
1268 #: build/C/man3/pthread_attr_setguardsize.3:24 build/C/man3/pthread_attr_setscope.3:24 build/C/man3/pthread_attr_setstack.3:24 build/C/man3/pthread_attr_setstackaddr.3:24 build/C/man3/pthread_self.3:24
1274 #: build/C/man3/pthread_attr_setguardsize.3:28
1276 "pthread_attr_setguardsize, pthread_attr_getguardsize - set/get guard size "
1277 "attribute in thread attributes object"
1281 #: build/C/man3/pthread_attr_setguardsize.3:36
1284 "B<int pthread_attr_setguardsize(pthread_attr_t *>I<attr>B<, size_t "
1285 ">I<guardsize>B<);>\n"
1286 "B<int pthread_attr_getguardsize(pthread_attr_t *>I<attr>B<, size_t "
1287 "*>I<guardsize>B<);>\n"
1291 #: build/C/man3/pthread_attr_setguardsize.3:47
1293 "The B<pthread_attr_setguardsize>() function sets the guard size attribute "
1294 "of the thread attributes object referred to by I<attr> to the value "
1295 "specified in I<guardsize>."
1299 #: build/C/man3/pthread_attr_setguardsize.3:57
1301 "If I<guardsize> is greater than 0, then for each new thread created using "
1302 "I<attr> the system allocates an additional region of at least I<guardsize> "
1303 "bytes at the end of the thread's stack to act as the guard area for the "
1304 "stack (but see BUGS)."
1308 #: build/C/man3/pthread_attr_setguardsize.3:63
1310 "If I<guardsize> is 0, then new threads created with I<attr> will not have a "
1315 #: build/C/man3/pthread_attr_setguardsize.3:65
1316 msgid "The default guard size is the same as the system page size."
1320 #: build/C/man3/pthread_attr_setguardsize.3:80
1322 "If the stack address attribute has been set in I<attr> (using "
1323 "B<pthread_attr_setstack>(3) or B<pthread_attr_setstackaddr>(3)), meaning "
1324 "that the caller is allocating the thread's stack, then the guard size "
1325 "attribute is ignored (i.e., no guard area is created by the system): it is "
1326 "the application's responsibility to handle stack overflow (perhaps by using "
1327 "B<mprotect>(2) to manually define a guard area at the end of the stack that "
1328 "it has allocated)."
1332 #: build/C/man3/pthread_attr_setguardsize.3:88
1334 "The B<pthread_attr_getguardsize>() function returns the guard size "
1335 "attribute of the thread attributes object referred to by I<attr> in the "
1336 "buffer pointed to by I<guardsize>."
1340 #: build/C/man3/pthread_attr_setguardsize.3:102
1342 "POSIX.1-2001 documents an B<EINVAL> error if I<attr> or I<guardsize> is "
1343 "invalid. On Linux these functions always succeed (but portable and "
1344 "future-proof applications should nevertheless handle a possible error "
1349 #: build/C/man3/pthread_attr_setguardsize.3:104 build/C/man3/pthread_attr_setstackaddr.3:81 build/C/man3/pthread_attr_setstacksize.3:81
1350 msgid "These functions are provided by glibc since version 2.1."
1354 #: build/C/man3/pthread_attr_setguardsize.3:120
1356 "A guard area consists of virtual memory pages that are protected to prevent "
1357 "read and write access. If a thread overflows its stack into the guard area, "
1358 "then, on most hard architectures, it receives a B<SIGSEGV> signal, thus "
1359 "notifying it of the overflow. Guard areas start on page boundaries, and the "
1360 "guard size is internally rounded up to the system page size when creating a "
1361 "thread. (Nevertheless, B<pthread_attr_getguardsize>() returns the guard "
1362 "size that was set by B<pthread_attr_setguardsize>().)"
1366 #: build/C/man3/pthread_attr_setguardsize.3:124
1368 "Setting a guard size of 0 may be useful to save memory in an application "
1369 "that creates many threads and knows that stack overflow can never occur."
1373 #: build/C/man3/pthread_attr_setguardsize.3:128
1375 "Choosing a guard size larger than the default size may be necessary for "
1376 "detecting stack overflows if a thread allocates large data structures on the "
1381 #: build/C/man3/pthread_attr_setguardsize.3:128 build/C/man3/pthread_attr_setinheritsched.3:101 build/C/man3/pthread_attr_setstacksize.3:94 build/C/man3/pthread_create.3:194 build/C/man3/pthread_exit.3:91
1387 #: build/C/man3/pthread_attr_setguardsize.3:139
1389 "As at glibc 2.8, the NPTL threading implementation includes the guard area "
1390 "within the stack size allocation, rather than allocating extra space at the "
1391 "end of the stack, as POSIX.1 requires. (This can result in an B<EINVAL> "
1392 "error from B<pthread_create>(3) if the guard size value is too large, "
1393 "leaving no space for the actual stack.)"
1396 #. glibc includes the guardsize within the allocated stack size,
1397 #. which looks pretty clearly to be in violation of POSIX.
1399 #. Filed bug, 22 Oct 2008:
1400 #. http://sources.redhat.com/bugzilla/show_bug.cgi?id=6973
1403 #. https//bugzilla.redhat.com/show_bug.cgi?id=435337
1404 #. Reportedly, LinuxThreads did the right thing, allocating
1405 #. extra space at the end of the stack:
1406 #. http://sourceware.org/ml/libc-alpha/2008-05/msg00086.html
1408 #: build/C/man3/pthread_attr_setguardsize.3:153
1410 "The obsolete LinuxThreads implementation did the right thing, allocating "
1411 "extra space at the end of the stack for the guard area."
1415 #: build/C/man3/pthread_attr_setguardsize.3:156
1416 msgid "See B<pthread_getattr_np>(3)."
1420 #: build/C/man3/pthread_attr_setguardsize.3:163
1422 "B<mmap>(2), B<mprotect>(2), B<pthread_attr_init>(3), "
1423 "B<pthread_attr_setstack>(3), B<pthread_attr_setstacksize>(3), "
1424 "B<pthread_create>(3), B<pthreads>(7)"
1428 #: build/C/man3/pthread_attr_setinheritsched.3:24
1430 msgid "PTHREAD_ATTR_SETINHERITSCHED"
1434 #: build/C/man3/pthread_attr_setinheritsched.3:24 build/C/man3/pthread_attr_setschedparam.3:24 build/C/man3/pthread_attr_setstacksize.3:24 build/C/man3/pthread_create.3:24
1440 #: build/C/man3/pthread_attr_setinheritsched.3:28
1442 "pthread_attr_setinheritsched, pthread_attr_getinheritsched - set/get inherit "
1443 "scheduler attribute in thread attributes object"
1447 #: build/C/man3/pthread_attr_setinheritsched.3:36
1450 "B<int pthread_attr_setinheritsched(pthread_attr_t *>I<attr>B<,>\n"
1451 "B< int >I<inheritsched>B<);>\n"
1452 "B<int pthread_attr_getinheritsched(pthread_attr_t *>I<attr>B<,>\n"
1453 "B< int *>I<inheritsched>B<);>\n"
1457 #: build/C/man3/pthread_attr_setinheritsched.3:53
1459 "The B<pthread_attr_setinheritsched>() function sets the inherit scheduler "
1460 "attribute of the thread attributes object referred to by I<attr> to the "
1461 "value specified in I<inheritsched>. The inherit scheduler attribute "
1462 "determines whether a thread created using the thread attributes object "
1463 "I<attr> will inherit its scheduling attributes from the calling thread or "
1464 "whether it will take them from I<attr>."
1468 #: build/C/man3/pthread_attr_setinheritsched.3:56
1469 msgid "The following values may be specified in I<inheritsched>:"
1473 #: build/C/man3/pthread_attr_setinheritsched.3:56
1475 msgid "B<PTHREAD_INHERIT_SCHED>"
1479 #: build/C/man3/pthread_attr_setinheritsched.3:64
1481 "Threads that are created using I<attr> inherit scheduling attributes from "
1482 "the creating thread; the scheduling attributes in I<attr> are ignored."
1486 #: build/C/man3/pthread_attr_setinheritsched.3:64
1488 msgid "B<PTHREAD_EXPLICIT_SCHED>"
1491 #. FIXME what are the defaults for scheduler settings?
1493 #: build/C/man3/pthread_attr_setinheritsched.3:71
1495 "Threads that are created using I<attr> take their scheduling attributes from "
1496 "the values specified by the attributes object."
1500 #: build/C/man3/pthread_attr_setinheritsched.3:75
1502 "The default setting of the inherit scheduler attribute in a newly "
1503 "initialized thread attributes object is B<PTHREAD_INHERIT_SCHED>."
1507 #: build/C/man3/pthread_attr_setinheritsched.3:82
1509 "The B<pthread_attr_getinheritsched>() returns the inherit scheduler "
1510 "attribute of the thread attributes object I<attr> in the buffer pointed to "
1511 "by I<inheritsched>."
1515 #: build/C/man3/pthread_attr_setinheritsched.3:88
1516 msgid "B<pthread_attr_setinheritsched>() can fail with the following error:"
1520 #: build/C/man3/pthread_attr_setinheritsched.3:92
1521 msgid "Invalid value in I<inheritsched>."
1525 #. Available since glibc 2.0.
1527 #: build/C/man3/pthread_attr_setinheritsched.3:99
1529 "POSIX.1-2001 also documents an optional B<ENOTSUP> error (\"attempt was made "
1530 "to set the attribute to an unsupported value\") for "
1531 "B<pthread_attr_setinheritsched>()."
1534 #. FIXME . Track status of the following bug:
1535 #. http://sourceware.org/bugzilla/show_bug.cgi?id=7007
1537 #: build/C/man3/pthread_attr_setinheritsched.3:117
1539 "As at glibc 2.8, if a thread attributes object is initialized using "
1540 "B<pthread_attr_init>(3), then the scheduling policy of the attributes object "
1541 "is set to B<SCHED_OTHER> and the scheduling priority is set to 0. However, "
1542 "if the inherit scheduler attribute is then set to B<PTHREAD_EXPLICIT_SCHED>, "
1543 "then a thread created using the attribute object wrongly inherits its "
1544 "scheduling attributes from the creating thread. This bug does not occur if "
1545 "either the scheduling policy or scheduling priority attribute is explicitly "
1546 "set in the thread attributes object before calling B<pthread_create>(3)."
1550 #: build/C/man3/pthread_attr_setinheritsched.3:120 build/C/man3/pthread_attr_setschedparam.3:96 build/C/man3/pthread_attr_setschedpolicy.3:92
1551 msgid "See B<pthread_setschedparam>(3)."
1555 #: build/C/man3/pthread_attr_setinheritsched.3:128
1557 "B<sched_setscheduler>(2), B<pthread_attr_init>(3), "
1558 "B<pthread_attr_setschedparam>(3), B<pthread_attr_setschedpolicy>(3), "
1559 "B<pthread_create>(3), B<pthread_setschedparam>(3), "
1560 "B<pthread_setschedprio>(3), B<pthreads>(7)"
1564 #: build/C/man3/pthread_attr_setschedparam.3:24
1566 msgid "PTHREAD_ATTR_SETSCHEDPARAM"
1570 #: build/C/man3/pthread_attr_setschedparam.3:28
1572 "pthread_attr_setschedparam, pthread_attr_getschedparam - set/get scheduling "
1573 "parameter attributes in thread attributes object"
1577 #: build/C/man3/pthread_attr_setschedparam.3:36
1580 "B<int pthread_attr_setschedparam(pthread_attr_t *>I<attr>B<,>\n"
1581 "B< const struct sched_param *>I<param>B<);>\n"
1582 "B<int pthread_attr_getschedparam(pthread_attr_t *>I<attr>B<,>\n"
1583 "B< struct sched_param *>I<param>B<);>\n"
1587 #: build/C/man3/pthread_attr_setschedparam.3:50
1589 "The B<pthread_attr_setschedparam>() function sets the scheduling parameter "
1590 "attributes of the thread attributes object referred to by I<attr> to the "
1591 "values specified in the buffer pointed to by I<param>. These attributes "
1592 "determine the scheduling parameters of a thread created using the thread "
1593 "attributes object I<attr>."
1597 #: build/C/man3/pthread_attr_setschedparam.3:57
1599 "The B<pthread_attr_getschedparam>() returns the scheduling parameter "
1600 "attributes of the thread attributes object I<attr> in the buffer pointed to "
1605 #: build/C/man3/pthread_attr_setschedparam.3:59
1606 msgid "Scheduling parameters are maintained in the following structure:"
1610 #: build/C/man3/pthread_attr_setschedparam.3:65 build/C/man3/pthread_setschedparam.3:67
1613 "struct sched_param {\n"
1614 " int sched_priority; /* Scheduling priority */\n"
1619 #: build/C/man3/pthread_attr_setschedparam.3:72 build/C/man3/pthread_setschedparam.3:74
1621 "As can be seen, only one scheduling parameter is supported. For details of "
1622 "the permitted ranges for scheduling priorities in each scheduling policy, "
1623 "see B<sched_setscheduler>(2)."
1627 #. Available since glibc 2.0.
1629 #: build/C/man3/pthread_attr_setschedparam.3:87
1631 "POSIX.1 documents B<EINVAL> and B<ENOTSUP> errors for "
1632 "B<pthread_attr_setschedparam>(). On Linux these functions always succeed "
1633 "(but portable and future-proof applications should nevertheless handle a "
1634 "possible error return)."
1638 #: build/C/man3/pthread_attr_setschedparam.3:93
1640 "See B<pthread_attr_setschedpolicy>(3) for a list of the thread scheduling "
1641 "policies supported on Linux."
1645 #: build/C/man3/pthread_attr_setschedparam.3:105
1647 "B<sched_get_priority_min>(2), B<sched_setscheduler>(2), "
1648 "B<pthread_attr_init>(3), B<pthread_attr_setinheritsched>(3), "
1649 "B<pthread_attr_setschedpolicy>(3), B<pthread_create>(3), "
1650 "B<pthread_setschedparam>(3), B<pthread_setschedprio>(3), B<pthreads>(7)"
1654 #: build/C/man3/pthread_attr_setschedpolicy.3:24
1656 msgid "PTHREAD_ATTR_SETSCHEDPOLICY"
1660 #: build/C/man3/pthread_attr_setschedpolicy.3:28
1662 "pthread_attr_setschedpolicy, pthread_attr_getschedpolicy - set/get "
1663 "scheduling policy attribute in thread attributes object"
1667 #: build/C/man3/pthread_attr_setschedpolicy.3:36
1670 "B<int pthread_attr_setschedpolicy(pthread_attr_t *>I<attr>B<, int "
1672 "B<int pthread_attr_getschedpolicy(pthread_attr_t *>I<attr>B<, int "
1673 ">I<*policy>B<);>\n"
1677 #: build/C/man3/pthread_attr_setschedpolicy.3:50
1679 "The B<pthread_attr_setschedpolicy>() function sets the scheduling policy "
1680 "attribute of the thread attributes object referred to by I<attr> to the "
1681 "value specified in I<policy>. This attribute determines the scheduling "
1682 "policy of a thread created using the thread attributes object I<attr>."
1685 #. FIXME . pthread_setschedparam() places no restriction on the policy,
1686 #. but pthread_attr_setschedpolicy() restricts policy to RR/FIFO/OTHER
1687 #. http://sourceware.org/bugzilla/show_bug.cgi?id=7013
1689 #: build/C/man3/pthread_attr_setschedpolicy.3:63
1691 "The supported values for I<policy> are B<SCHED_FIFO>, B<SCHED_RR>, and "
1692 "B<SCHED_OTHER>, with the semantics described in B<sched_setscheduler>(2)."
1696 #: build/C/man3/pthread_attr_setschedpolicy.3:70
1698 "The B<pthread_attr_getschedpolicy>() returns the scheduling policy "
1699 "attribute of the thread attributes object I<attr> in the buffer pointed to "
1704 #: build/C/man3/pthread_attr_setschedpolicy.3:76
1705 msgid "B<pthread_attr_setschedpolicy>() can fail with the following error:"
1709 #: build/C/man3/pthread_attr_setschedpolicy.3:80
1710 msgid "Invalid value in I<policy>."
1714 #. Available since glibc 2.0.
1716 #: build/C/man3/pthread_attr_setschedpolicy.3:87
1718 "POSIX.1-2001 also documents an optional B<ENOTSUP> error (\"attempt was made "
1719 "to set the attribute to an unsupported value\") for "
1720 "B<pthread_attr_setschedpolicy>()."
1724 #: build/C/man3/pthread_attr_setschedpolicy.3:100
1726 "B<sched_setscheduler>(2), B<pthread_attr_init>(3), "
1727 "B<pthread_attr_setinheritsched>(3), B<pthread_attr_setschedparam>(3), "
1728 "B<pthread_create>(3), B<pthread_setschedparam>(3), "
1729 "B<pthread_setschedprio>(3), B<pthreads>(7)"
1733 #: build/C/man3/pthread_attr_setscope.3:24
1735 msgid "PTHREAD_ATTR_SETSCOPE"
1739 #: build/C/man3/pthread_attr_setscope.3:28
1741 "pthread_attr_setscope, pthread_attr_getscope - set/get contention scope "
1742 "attribute in thread attributes object"
1746 #: build/C/man3/pthread_attr_setscope.3:36
1749 "B<int pthread_attr_setscope(pthread_attr_t *>I<attr>B<, int >I<scope>B<);>\n"
1750 "B<int pthread_attr_getscope(pthread_attr_t *>I<attr>B<, int "
1755 #: build/C/man3/pthread_attr_setscope.3:51
1757 "The B<pthread_attr_setscope>() function sets the contention scope attribute "
1758 "of the thread attributes object referred to by I<attr> to the value "
1759 "specified in I<scope>. The contention scope attribute defines the set of "
1760 "threads against which a thread competes for resources such as the CPU. "
1761 "POSIX.1-2001 specifies two possible values for I<scope>:"
1765 #: build/C/man3/pthread_attr_setscope.3:51
1767 msgid "B<PTHREAD_SCOPE_SYSTEM>"
1771 #: build/C/man3/pthread_attr_setscope.3:59
1773 "The thread competes for resources with all other threads in all processes on "
1774 "the system that are in the same scheduling allocation domain (a group of one "
1775 "or more processors). B<PTHREAD_SCOPE_SYSTEM> threads are scheduled relative "
1776 "to one another according to their scheduling policy and priority."
1780 #: build/C/man3/pthread_attr_setscope.3:59
1782 msgid "B<PTHREAD_SCOPE_PROCESS>"
1786 #: build/C/man3/pthread_attr_setscope.3:74
1788 "The thread competes for resources with all other threads in the same process "
1789 "that were also created with the B<PTHREAD_SCOPE_PROCESS> contention scope. "
1790 "B<PTHREAD_SCOPE_PROCESS> threads are scheduled relative to other threads in "
1791 "the process according to their scheduling policy and priority. POSIX.1-2001 "
1792 "leaves it unspecified how these threads contend with other threads in other "
1793 "process on the system or with other threads in the same process that were "
1794 "created with the B<PTHREAD_SCOPE_SYSTEM> contention scope."
1798 #: build/C/man3/pthread_attr_setscope.3:81
1800 "POSIX.1-2001 only requires that an implementation support one of these "
1801 "contention scopes, but permits both to be supported. Linux supports "
1802 "B<PTHREAD_SCOPE_SYSTEM>, but not B<PTHREAD_SCOPE_PROCESS>."
1806 #: build/C/man3/pthread_attr_setscope.3:89
1808 "The B<pthread_attr_getscope>() function returns the contention scope "
1809 "attribute of the thread attributes object referred to by I<attr> in the "
1810 "buffer pointed to by I<scope>."
1814 #: build/C/man3/pthread_attr_setscope.3:95
1815 msgid "B<pthread_attr_setscope>() can fail with the following errors:"
1819 #: build/C/man3/pthread_attr_setscope.3:99
1820 msgid "An invalid value was specified in I<scope>."
1824 #: build/C/man3/pthread_attr_setscope.3:99
1830 #: build/C/man3/pthread_attr_setscope.3:105
1832 "I<scope> specified the value B<PTHREAD_SCOPE_PROCESS>, which is not "
1833 "supported on Linux."
1837 #: build/C/man3/pthread_attr_setscope.3:115
1839 "The B<PTHREAD_SCOPE_SYSTEM> contention scope typically indicates that a "
1840 "userspace thread is bound directly to a single kernel-scheduling entity. "
1841 "This is the case on Linux for the obsolete LinuxThreads implementation and "
1842 "the modern NPTL implementation, which are both 1:1 threading "
1847 #: build/C/man3/pthread_attr_setscope.3:118
1849 "POSIX.1-2001 specifies that the default contention scope is "
1850 "implementation-defined."
1854 #: build/C/man3/pthread_attr_setscope.3:125
1856 "B<pthread_attr_init>(3), B<pthread_attr_setaffinity_np>(3), "
1857 "B<pthread_attr_setinheritsched>(3), B<pthread_attr_setschedparam>(3), "
1858 "B<pthread_attr_setschedpolicy>(3), B<pthread_create>(3), B<pthreads>(7)"
1862 #: build/C/man3/pthread_attr_setstack.3:24
1864 msgid "PTHREAD_ATTR_SETSTACK"
1868 #: build/C/man3/pthread_attr_setstack.3:28
1870 "pthread_attr_setstack, pthread_attr_getstack - set/get stack attributes in "
1871 "thread attributes object"
1875 #: build/C/man3/pthread_attr_setstack.3:36
1878 "B<int pthread_attr_setstack(pthread_attr_t *>I<attr>B<,>\n"
1879 "B< void *>I<stackaddr>B<, size_t "
1880 ">I<stacksize>B<);>\n"
1881 "B<int pthread_attr_getstack(pthread_attr_t *>I<attr>B<,>\n"
1882 "B< void **>I<stackaddr>B<, size_t "
1883 "*>I<stacksize>B<);>\n"
1887 #: build/C/man3/pthread_attr_setstack.3:43 build/C/man3/pthread_sigqueue.3:39
1888 msgid "Feature Test Macro Requirements for glibc (see B<feature_test_macros>(7)):"
1892 #: build/C/man3/pthread_attr_setstack.3:48
1893 msgid "B<pthread_attr_getstack>(), B<pthread_attr_setstack>():"
1897 #: build/C/man3/pthread_attr_setstack.3:50
1898 msgid "_POSIX_C_SOURCE\\ E<gt>=\\ 200112L || _XOPEN_SOURCE\\ E<gt>=\\ 600"
1902 #: build/C/man3/pthread_attr_setstack.3:66
1904 "The B<pthread_attr_setstack>() function sets the stack address and stack "
1905 "size attributes of the thread attributes object referred to by I<attr> to "
1906 "the values specified in I<stackaddr> and I<stacksize>, respectively. These "
1907 "attributes specify the location and size of the stack that should be used by "
1908 "a thread that is created using the thread attributes object I<attr>."
1912 #: build/C/man3/pthread_attr_setstack.3:72
1914 "I<stackaddr> should point to the lowest addressable byte of a buffer of "
1915 "I<stacksize> bytes that was allocated by the caller. The pages of the "
1916 "allocated buffer should be both readable and writable."
1920 #: build/C/man3/pthread_attr_setstack.3:83
1922 "The B<pthread_attr_getstack>() function returns the stack address and stack "
1923 "size attributes of the thread attributes object referred to by I<attr> in "
1924 "the buffers pointed to by I<stackaddr> and I<stacksize>, respectively."
1928 #: build/C/man3/pthread_attr_setstack.3:89
1929 msgid "B<pthread_attr_setstack>() can fail with the following error:"
1933 #: build/C/man3/pthread_attr_setstack.3:100
1935 "I<stacksize> is less than B<PTHREAD_STACK_MIN> (16384) bytes. On some "
1936 "systems, this error may also occur if I<stackaddr> or I<stackaddr\\ +\\ "
1937 "stacksize> is not suitably aligned."
1941 #: build/C/man3/pthread_attr_setstack.3:108
1943 "POSIX.1-2001 also documents an B<EACCES> error if the stack area described "
1944 "by I<stackaddr> and I<stacksize> is not both readable and writable by the "
1949 #: build/C/man3/pthread_attr_setstack.3:110
1950 msgid "These functions are provided by glibc since version 2.2."
1954 #: build/C/man3/pthread_attr_setstack.3:120
1956 "These functions are provided for applications that must ensure that a "
1957 "thread's stack is placed in a particular location. For most applications, "
1958 "this is not necessary, and the use of these functions should be avoided. "
1959 "(Use B<pthread_attr_setstacksize>(3) if an application simply requires a "
1960 "stack size other than the default.)"
1964 #: build/C/man3/pthread_attr_setstack.3:131
1966 "When an application employs B<pthread_attr_setstack>(), it takes over the "
1967 "responsibility of allocating the stack. Any guard size value that was set "
1968 "using B<pthread_attr_setguardsize>(3) is ignored. If deemed necessary, it "
1969 "is the application's responsibility to allocate a guard area (one or more "
1970 "pages protected against reading and writing) to handle the possibility of "
1975 #: build/C/man3/pthread_attr_setstack.3:142
1977 "The address specified in I<stackaddr> should be suitably aligned: for full "
1978 "portability, align it on a page boundary (I<sysconf(_SC_PAGESIZE)>). "
1979 "B<posix_memalign>(3) may be useful for allocation. Probably, I<stacksize> "
1980 "should also be a multiple of the system page size."
1984 #: build/C/man3/pthread_attr_setstack.3:151
1986 "If I<attr> is used to create multiple threads, then the caller must change "
1987 "the stack address attribute between calls to B<pthread_create>(3); "
1988 "otherwise, the threads will attempt to use the same memory area for their "
1989 "stacks, and chaos will ensue."
1993 #: build/C/man3/pthread_attr_setstack.3:163
1995 "B<mmap>(2), B<mprotect>(2), B<posix_memalign>(3), B<pthread_attr_init>(3), "
1996 "B<pthread_attr_setguardsize>(3), B<pthread_attr_setstackaddr>(3), "
1997 "B<pthread_attr_setstacksize>(3), B<pthread_create>(3), B<pthreads>(7)"
2001 #: build/C/man3/pthread_attr_setstackaddr.3:24
2003 msgid "PTHREAD_ATTR_SETSTACKADDR"
2007 #: build/C/man3/pthread_attr_setstackaddr.3:28
2009 "pthread_attr_setstackaddr, pthread_attr_getstackaddr - set/get stack address "
2010 "attribute in thread attributes object"
2014 #: build/C/man3/pthread_attr_setstackaddr.3:36
2017 "B<int pthread_attr_setstackaddr(pthread_attr_t *>I<attr>B<, void "
2018 "*>I<stackaddr>B<);>\n"
2019 "B<int pthread_attr_getstackaddr(pthread_attr_t *>I<attr>B<, void "
2020 "**>I<stackaddr>B<);>\n"
2024 #: build/C/man3/pthread_attr_setstackaddr.3:47
2026 "These functions are obsolete: B<do not use them.> Use "
2027 "B<pthread_attr_setstack>(3) and B<pthread_attr_getstack>(3) instead."
2031 #: build/C/man3/pthread_attr_setstackaddr.3:58
2033 "The B<pthread_attr_setstackaddr>() function sets the stack address "
2034 "attribute of the thread attributes object referred to by I<attr> to the "
2035 "value specified in I<stackaddr>. This attribute specifies the location of "
2036 "the stack that should be used by a thread that is created using the thread "
2037 "attributes object I<attr>."
2041 #: build/C/man3/pthread_attr_setstackaddr.3:64
2043 "I<stackaddr> should point to a buffer of at least B<PTHREAD_STACK_MIN> bytes "
2044 "that was allocated by the caller. The pages of the allocated buffer should "
2045 "be both readable and writable."
2049 #: build/C/man3/pthread_attr_setstackaddr.3:72
2051 "The B<pthread_attr_getstackaddr>() function returns the stack address "
2052 "attribute of the thread attributes object referred to by I<attr> in the "
2053 "buffer pointed to by I<stackaddr>."
2057 #: build/C/man3/pthread_attr_setstackaddr.3:79
2059 "No errors are defined (but applications should nevertheless handle a "
2060 "possible error return)."
2064 #: build/C/man3/pthread_attr_setstackaddr.3:84
2066 "POSIX.1-2001 specifies these functions but marks them as obsolete. "
2067 "POSIX.1-2008 removes the specification of these functions."
2071 #: build/C/man3/pthread_attr_setstackaddr.3:108
2073 "I<Do not use these functions!> They cannot be portably used, since they "
2074 "provide no way of specifying the direction of growth or the range of the "
2075 "stack. For example, on architectures with a stack that grows downward, "
2076 "I<stackaddr> specifies the next address past the I<highest> address of the "
2077 "allocated stack area. However, on architectures with a stack that grows "
2078 "upward, I<stackaddr> specifies the I<lowest> address in the allocated stack "
2079 "area. By contrast, the I<stackaddr> used by B<pthread_attr_setstack>(3) "
2080 "and B<pthread_attr_getstack>(3), is always a pointer to the lowest address "
2081 "in the allocated stack area (and the I<stacksize> argument specifies the "
2082 "range of the stack)."
2086 #: build/C/man3/pthread_attr_setstackaddr.3:113
2088 "B<pthread_attr_init>(3), B<pthread_attr_setstack>(3), "
2089 "B<pthread_attr_setstacksize>(3), B<pthread_create>(3), B<pthreads>(7)"
2093 #: build/C/man3/pthread_attr_setstacksize.3:24
2095 msgid "PTHREAD_ATTR_SETSTACKSIZE"
2099 #: build/C/man3/pthread_attr_setstacksize.3:28
2101 "pthread_attr_setstacksize, pthread_attr_getstacksize - set/get stack size "
2102 "attribute in thread attributes object"
2106 #: build/C/man3/pthread_attr_setstacksize.3:36
2109 "B<int pthread_attr_setstacksize(pthread_attr_t *>I<attr>B<, size_t "
2110 ">I<stacksize>B<);>\n"
2111 "B<int pthread_attr_getstacksize(pthread_attr_t *>I<attr>B<, size_t "
2112 "*>I<stacksize>B<);>\n"
2116 #: build/C/man3/pthread_attr_setstacksize.3:47
2118 "The B<pthread_attr_setstacksize>() function sets the stack size attribute "
2119 "of the thread attributes object referred to by I<attr> to the value "
2120 "specified in I<stacksize>."
2124 #: build/C/man3/pthread_attr_setstacksize.3:51
2126 "The stack size attribute determines the minimum size (in bytes) that will be "
2127 "allocated for threads created using the thread attributes object I<attr>."
2131 #: build/C/man3/pthread_attr_setstacksize.3:59
2133 "The B<pthread_attr_getstacksize>() function returns the stack size "
2134 "attribute of the thread attributes object referred to by I<attr> in the "
2135 "buffer pointed to by I<stacksize>."
2139 #: build/C/man3/pthread_attr_setstacksize.3:65
2140 msgid "B<pthread_attr_setstacksize>() can fail with the following error:"
2144 #: build/C/man3/pthread_attr_setstacksize.3:70
2145 msgid "The stack size is less than B<PTHREAD_STACK_MIN> (16384) bytes."
2150 #: build/C/man3/pthread_attr_setstacksize.3:79
2152 "On some systems, B<pthread_attr_setstacksize>() can fail with the error "
2153 "B<EINVAL> if I<stacksize> is not a multiple of the system page size."
2157 #: build/C/man3/pthread_attr_setstacksize.3:86
2159 "For details on the default stack size of new threads, see "
2160 "B<pthread_create>(3)."
2164 #: build/C/man3/pthread_attr_setstacksize.3:89
2166 "A thread's stack size is fixed at the time of thread creation. Only the "
2167 "main thread can dynamically grow its stack."
2171 #: build/C/man3/pthread_attr_setstacksize.3:94
2173 "The B<pthread_attr_setstack>(3) function allows an application to set both "
2174 "the size and location of a caller-allocated stack that is to be used by a "
2179 #: build/C/man3/pthread_attr_setstacksize.3:106
2181 "As at glibc 2.8, if the specified I<stacksize> is not a multiple of "
2182 "B<STACK_ALIGN> (16 bytes on most architectures), it may be rounded "
2183 "I<downward>, in violation of POSIX.1-2001, which says that the allocated "
2184 "stack will be at least I<stacksize> bytes."
2188 #: build/C/man3/pthread_attr_setstacksize.3:109 build/C/man3/pthread_join.3:125
2189 msgid "See B<pthread_create>(3)."
2193 #: build/C/man3/pthread_attr_setstacksize.3:115
2195 "B<getrlimit>(2), B<pthread_attr_init>(3), B<pthread_attr_setguardsize>(3), "
2196 "B<pthread_attr_setstack>(3), B<pthread_create>(3), B<pthreads>(7)"
2200 #: build/C/man3/pthread_cancel.3:24
2202 msgid "PTHREAD_CANCEL"
2206 #: build/C/man3/pthread_cancel.3:24 build/C/man3/pthread_setschedparam.3:24
2212 #: build/C/man3/pthread_cancel.3:27
2213 msgid "pthread_cancel - send a cancellation request to a thread"
2217 #: build/C/man3/pthread_cancel.3:32
2219 msgid "B<int pthread_cancel(pthread_t >I<thread>B<);>\n"
2223 #: build/C/man3/pthread_cancel.3:44
2225 "The B<pthread_cancel>() function sends a cancellation request to the thread "
2226 "I<thread>. Whether and when the target thread reacts to the cancellation "
2227 "request depends on two attributes that are under the control of that thread: "
2228 "its cancelability I<state> and I<type>."
2232 #: build/C/man3/pthread_cancel.3:56
2234 "A thread's cancelability state, determined by B<pthread_setcancelstate>(3), "
2235 "can be I<enabled> (the default for new threads) or I<disabled>. If a thread "
2236 "has disabled cancellation, then a cancellation request remains queued until "
2237 "the thread enables cancellation. If a thread has enabled cancellation, then "
2238 "its cancelability type determines when cancellation occurs."
2242 #: build/C/man3/pthread_cancel.3:72
2244 "A thread's cancellation type, determined by B<pthread_setcanceltype>(3), may "
2245 "be either I<asynchronous> or I<deferred> (the default for new threads). "
2246 "Asynchronous cancelability means that the thread can be canceled at any time "
2247 "(usually immediately, but the system does not guarantee this). Deferred "
2248 "cancelability means that cancellation will be delayed until the thread next "
2249 "calls a function that is a I<cancellation point>. A list of functions that "
2250 "are or may be cancellation points is provided in I<pthreads>(7)."
2254 #: build/C/man3/pthread_cancel.3:76
2256 "When a cancellation requested is acted on, the following steps occur for "
2257 "I<thread> (in this order):"
2261 #: build/C/man3/pthread_cancel.3:76 build/C/man3/pthread_cleanup_push.3:67
2267 #: build/C/man3/pthread_cancel.3:81
2269 "Cancellation clean-up handlers are popped (in the reverse of the order in "
2270 "which they were pushed) and called. (See B<pthread_cleanup_push>(3).)"
2274 #: build/C/man3/pthread_cancel.3:81 build/C/man3/pthread_cleanup_push.3:71
2280 #: build/C/man3/pthread_cancel.3:86
2282 "Thread-specific data destructors are called, in an unspecified order. (See "
2283 "B<pthread_key_create>(3).)"
2287 #: build/C/man3/pthread_cancel.3:86 build/C/man3/pthread_cleanup_push.3:79
2293 #: build/C/man3/pthread_cancel.3:90
2294 msgid "The thread is terminated. (See B<pthread_exit>(3).)"
2298 #: build/C/man3/pthread_cancel.3:98
2300 "The above steps happen asynchronously with respect to the "
2301 "B<pthread_cancel>() call; the return status of B<pthread_cancel>() merely "
2302 "informs the caller whether the cancellation request was successfully queued."
2306 #: build/C/man3/pthread_cancel.3:107
2308 "After a canceled thread has terminated, a join with that thread using "
2309 "B<pthread_join>(3) obtains B<PTHREAD_CANCELED> as the thread's exit "
2310 "status. (Joining with a thread is the only way to know that cancellation "
2315 #: build/C/man3/pthread_cancel.3:112
2317 "On success, B<pthread_cancel>() returns 0; on error, it returns a nonzero "
2322 #: build/C/man3/pthread_cancel.3:113 build/C/man3/pthread_detach.3:57 build/C/man3/pthread_getcpuclockid.3:56 build/C/man3/pthread_join.3:91 build/C/man3/pthread_kill.3:59 build/C/man3/pthread_setaffinity_np.3:112 build/C/man3/pthread_setschedparam.3:112 build/C/man3/pthread_setschedprio.3:68 build/C/man3/pthread_sigqueue.3:83
2328 #: build/C/man3/pthread_cancel.3:120 build/C/man3/pthread_detach.3:62 build/C/man3/pthread_getcpuclockid.3:61 build/C/man3/pthread_join.3:96 build/C/man3/pthread_kill.3:64 build/C/man3/pthread_setaffinity_np.3:117 build/C/man3/pthread_setschedparam.3:117 build/C/man3/pthread_setschedprio.3:73
2329 msgid "No thread with the ID I<thread> could be found."
2333 #: build/C/man3/pthread_cancel.3:130
2335 "On Linux, cancellation is implemented using signals. Under the NPTL "
2336 "threading implementation, the first real-time signal (i.e., signal 32) is "
2337 "used for this purpose. On LinuxThreads, the second real-time signal is "
2338 "used, if real-time signals are available, otherwise B<SIGUSR2> is used."
2342 #: build/C/man3/pthread_cancel.3:136
2344 "The program below creates a thread and then cancels it. The main thread "
2345 "joins with the canceled thread to check that its exit status was "
2346 "B<PTHREAD_CANCELED>. The following shell session shows what happens when we "
2351 #: build/C/man3/pthread_cancel.3:144
2355 "thread_func(): started; cancellation disabled\n"
2356 "main(): sending cancellation request\n"
2357 "thread_func(): about to enable cancellation\n"
2358 "main(): thread was canceled\n"
2362 #: build/C/man3/pthread_cancel.3:154
2365 "#include E<lt>pthread.hE<gt>\n"
2366 "#include E<lt>stdio.hE<gt>\n"
2367 "#include E<lt>errno.hE<gt>\n"
2368 "#include E<lt>stdlib.hE<gt>\n"
2369 "#include E<lt>unistd.hE<gt>\n"
2373 #: build/C/man3/pthread_cancel.3:162
2377 "thread_func(void *ignored_argument)\n"
2383 #: build/C/man3/pthread_cancel.3:165
2386 " /* Disable cancellation for a while, so that we don\\(aqt\n"
2387 " immediately react to a cancellation request */\n"
2391 #: build/C/man3/pthread_cancel.3:169
2394 " s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);\n"
2396 " handle_error_en(s, \"pthread_setcancelstate\");\n"
2400 #: build/C/man3/pthread_cancel.3:173
2403 " printf(\"thread_func(): started; cancellation disabled\\en\");\n"
2405 " printf(\"thread_func(): about to enable cancellation\\en\");\n"
2409 #: build/C/man3/pthread_cancel.3:177
2412 " s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);\n"
2414 " handle_error_en(s, \"pthread_setcancelstate\");\n"
2418 #: build/C/man3/pthread_cancel.3:179
2420 msgid " /* sleep() is a cancellation point */\n"
2424 #: build/C/man3/pthread_cancel.3:181
2426 msgid " sleep(1000); /* Should get canceled while we sleep */\n"
2430 #: build/C/man3/pthread_cancel.3:183
2432 msgid " /* Should never get here */\n"
2436 #: build/C/man3/pthread_cancel.3:187
2439 " printf(\"thread_func(): not canceled!\\en\");\n"
2445 #: build/C/man3/pthread_cancel.3:194
2457 #: build/C/man3/pthread_cancel.3:196
2459 msgid " /* Start a thread and then send it a cancellation request */\n"
2463 #: build/C/man3/pthread_cancel.3:200
2466 " s = pthread_create(&thr, NULL, &thread_func, NULL);\n"
2468 " handle_error_en(s, \"pthread_create\");\n"
2472 #: build/C/man3/pthread_cancel.3:202
2474 msgid " sleep(2); /* Give thread a chance to get started */\n"
2478 #: build/C/man3/pthread_cancel.3:207
2481 " printf(\"main(): sending cancellation request\\en\");\n"
2482 " s = pthread_cancel(thr);\n"
2484 " handle_error_en(s, \"pthread_cancel\");\n"
2488 #: build/C/man3/pthread_cancel.3:209
2490 msgid " /* Join with thread to see what its exit status was */\n"
2494 #: build/C/man3/pthread_cancel.3:213 build/C/man3/pthread_cleanup_push.3:301
2497 " s = pthread_join(thr, &res);\n"
2499 " handle_error_en(s, \"pthread_join\");\n"
2503 #: build/C/man3/pthread_cancel.3:220
2506 " if (res == PTHREAD_CANCELED)\n"
2507 " printf(\"main(): thread was canceled\\en\");\n"
2509 " printf(\"main(): thread wasn\\(aqt canceled (shouldn\\(aqt "
2510 "happen!)\\en\");\n"
2511 " exit(EXIT_SUCCESS);\n"
2516 #: build/C/man3/pthread_cancel.3:230
2518 "B<pthread_cleanup_push>(3), B<pthread_create>(3), B<pthread_exit>(3), "
2519 "B<pthread_join>(3), B<pthread_key_create>(3), B<pthread_setcancelstate>(3), "
2520 "B<pthread_setcanceltype>(3), B<pthread_testcancel>(3), B<pthreads>(7)"
2524 #: build/C/man3/pthread_cleanup_push.3:24
2526 msgid "PTHREAD_CLEANUP_PUSH"
2530 #: build/C/man3/pthread_cleanup_push.3:24 build/C/man3/pthread_setcancelstate.3:24
2536 #: build/C/man3/pthread_cleanup_push.3:28
2538 "pthread_cleanup_push, pthread_cleanup_pop - push and pop thread cancellation "
2543 #: build/C/man3/pthread_cleanup_push.3:35
2546 "B<void pthread_cleanup_push(void (*>I<routine>B<)(void *),>\n"
2547 "B< void *>I<arg>B<);>\n"
2548 "B<void pthread_cleanup_pop(int >I<execute>B<);>\n"
2552 #: build/C/man3/pthread_cleanup_push.3:46
2554 "These functions manipulate the calling thread's stack of thread-cancellation "
2555 "clean-up handlers. A clean-up handler is a function that is automatically "
2556 "executed when a thread is canceled (or in various other circumstances "
2557 "described below); it might, for example, unlock a mutex so that it becomes "
2558 "available to other threads in the process."
2562 #: build/C/man3/pthread_cleanup_push.3:57
2564 "The B<pthread_cleanup_push>() function pushes I<routine> onto the top of "
2565 "the stack of clean-up handlers. When I<routine> is later invoked, it will "
2566 "be given I<arg> as its argument."
2570 #: build/C/man3/pthread_cleanup_push.3:64
2572 "The B<pthread_cleanup_pop>() function removes the routine at the top of the "
2573 "stack of clean-up handlers, and optionally executes it if I<execute> is "
2578 #: build/C/man3/pthread_cleanup_push.3:67
2580 "A cancellation clean-up handler is popped from the stack and executed in the "
2581 "following circumstances:"
2585 #: build/C/man3/pthread_cleanup_push.3:71
2587 "When a thread is canceled, all of the stacked clean-up handlers are popped "
2588 "and executed in the reverse of the order in which they were pushed onto the "
2593 #: build/C/man3/pthread_cleanup_push.3:79
2595 "When a thread terminates by calling B<pthread_exit>(3), all clean-up "
2596 "handlers are executed as described in the preceding point. (Clean-up "
2597 "handlers are I<not> called if the thread terminates by performing a "
2598 "I<return> from the thread start function.)"
2602 #: build/C/man3/pthread_cleanup_push.3:85
2604 "When a thread calls B<pthread_cleanup_pop>() with a nonzero I<execute> "
2605 "argument, the top-most clean-up handler is popped and executed."
2609 #: build/C/man3/pthread_cleanup_push.3:97
2611 "POSIX.1 permits B<pthread_cleanup_push>() and B<pthread_cleanup_pop>() to "
2612 "be implemented as macros that expand to text containing \\(aqB<{>\\(aq and "
2613 "\\(aqB<}>\\(aq, respectively. For this reason, the caller must ensure that "
2614 "calls to these functions are paired within the same function, and at the "
2615 "same lexical nesting level. (In other words, a clean-up handler is only "
2616 "established during the execution of a specified section of code.)"
2620 #: build/C/man3/pthread_cleanup_push.3:117
2622 "Calling B<longjmp>(3) (B<siglongjmp>(3)) produces undefined results if any "
2623 "call has been made to B<pthread_cleanup_push>() or B<pthread_cleanup_pop>() "
2624 "without the matching call of the pair since the jump buffer was filled by "
2625 "B<setjmp>(3) (B<sigsetjmp>(3)). Likewise, calling B<longjmp>(3) "
2626 "(B<siglongjmp>(3)) from inside a clean-up handler produces undefined "
2627 "results unless the jump buffer was also filled by B<setjmp>(3) "
2628 "(B<sigsetjmp>(3)) inside the handler."
2632 #: build/C/man3/pthread_cleanup_push.3:119
2633 msgid "These functions do not return a value."
2637 #. Available since glibc 2.0
2639 #: build/C/man3/pthread_cleanup_push.3:123
2640 msgid "There are no errors."
2644 #: build/C/man3/pthread_cleanup_push.3:134
2646 "On Linux, the B<pthread_cleanup_push>() and B<pthread_cleanup_pop>() "
2647 "functions I<are> implemented as macros that expand to text containing "
2648 "\\(aqB<{>\\(aq and \\(aqB<}>\\(aq, respectively. This means that variables "
2649 "declared within the scope of paired calls to these functions will only be "
2650 "visible within that scope."
2653 #. The text was actually added in the 2004 TC2
2655 #: build/C/man3/pthread_cleanup_push.3:149
2657 "POSIX.1 says that the effect of using I<return>, I<break>, I<continue>, or "
2658 "I<goto> to prematurely leave a block bracketed B<pthread_cleanup_push>() "
2659 "and B<pthread_cleanup_pop>() is undefined. Portable applications should "
2664 #: build/C/man3/pthread_cleanup_push.3:164
2666 "The program below provides a simple example of the use of the functions "
2667 "described in this page. The program creates a thread that executes a loop "
2668 "bracketed by B<pthread_cleanup_push>() and B<pthread_cleanup_pop>(). This "
2669 "loop increments a global variable, I<cnt>, once each second. Depending on "
2670 "what command-line arguments are supplied, the main thread sends the other "
2671 "thread a cancellation request, or sets a global variable that causes the "
2672 "other thread to exit its loop and terminate normally (by doing a I<return>)."
2676 #: build/C/man3/pthread_cleanup_push.3:167
2678 "In the following shell session, the main thread sends a cancellation request "
2679 "to the other thread:"
2683 #: build/C/man3/pthread_cleanup_push.3:177
2687 "New thread started\n"
2690 "Canceling thread\n"
2691 "Called clean-up handler\n"
2692 "Thread was canceled; cnt = 0\n"
2696 #: build/C/man3/pthread_cleanup_push.3:185
2698 "From the above, we see that the thread was canceled, and that the "
2699 "cancellation clean-up handler was called and it reset the value of the "
2700 "global variable I<cnt> to 0."
2704 #: build/C/man3/pthread_cleanup_push.3:188
2706 "In the next run, the main program sets a global variable that causes other "
2707 "thread to terminate normally:"
2711 #: build/C/man3/pthread_cleanup_push.3:196
2715 "New thread started\n"
2718 "Thread terminated normally; cnt = 2\n"
2722 #: build/C/man3/pthread_cleanup_push.3:204
2724 "From the above, we see that the clean-up handler was not executed (because "
2725 "I<cleanup_pop_arg> was 0), and therefore the value of I<cnt> was not reset."
2729 #: build/C/man3/pthread_cleanup_push.3:209
2731 "In the next run, the main program sets a global variable that causes the "
2732 "other thread to terminate normally, and supplies a nonzero value for "
2733 "I<cleanup_pop_arg>:"
2737 #: build/C/man3/pthread_cleanup_push.3:218
2740 "$ B<./a.out x 1>\n"
2741 "New thread started\n"
2744 "Called clean-up handler\n"
2745 "Thread terminated normally; cnt = 0\n"
2749 #: build/C/man3/pthread_cleanup_push.3:225
2751 "In the above, we see that although the thread was not canceled, the clean-up "
2752 "handler was executed, because the argument given to B<pthread_cleanup_pop>() "
2757 #: build/C/man3/pthread_cleanup_push.3:234
2760 "#include E<lt>pthread.hE<gt>\n"
2761 "#include E<lt>sys/types.hE<gt>\n"
2762 "#include E<lt>stdio.hE<gt>\n"
2763 "#include E<lt>stdlib.hE<gt>\n"
2764 "#include E<lt>unistd.hE<gt>\n"
2765 "#include E<lt>errno.hE<gt>\n"
2769 #: build/C/man3/pthread_cleanup_push.3:241
2772 "static int done = 0;\n"
2773 "static int cleanup_pop_arg = 0;\n"
2774 "static int cnt = 0;\n"
2778 #: build/C/man3/pthread_cleanup_push.3:248
2782 "cleanup_handler(void *arg)\n"
2784 " printf(\"Called clean-up handler\\en\");\n"
2790 #: build/C/man3/pthread_cleanup_push.3:253
2794 "thread_start(void *arg)\n"
2796 " time_t start, curr;\n"
2800 #: build/C/man3/pthread_cleanup_push.3:255
2802 msgid " printf(\"New thread started\\en\");\n"
2806 #: build/C/man3/pthread_cleanup_push.3:257
2808 msgid " pthread_cleanup_push(cleanup_handler, NULL);\n"
2812 #: build/C/man3/pthread_cleanup_push.3:259
2814 msgid " curr = start = time(NULL);\n"
2818 #: build/C/man3/pthread_cleanup_push.3:268
2821 " while (!done) {\n"
2822 " pthread_testcancel(); /* A cancellation point */\n"
2823 " if (curr E<lt> time(NULL)) {\n"
2824 " curr = time(NULL);\n"
2825 " printf(\"cnt = %d\\en\", cnt); /* A cancellation point */\n"
2832 #: build/C/man3/pthread_cleanup_push.3:272
2835 " pthread_cleanup_pop(cleanup_pop_arg);\n"
2841 #: build/C/man3/pthread_cleanup_push.3:279
2845 "main(int argc, char *argv[])\n"
2853 #: build/C/man3/pthread_cleanup_push.3:283
2856 " s = pthread_create(&thr, NULL, thread_start, NULL);\n"
2858 " handle_error_en(s, \"pthread_create\");\n"
2862 #: build/C/man3/pthread_cleanup_push.3:285
2864 msgid " sleep(2); /* Allow new thread to run a while */\n"
2868 #: build/C/man3/pthread_cleanup_push.3:290
2871 " if (argc E<gt> 1) {\n"
2872 " if (argc E<gt> 2)\n"
2873 " cleanup_pop_arg = atoi(argv[2]);\n"
2878 #: build/C/man3/pthread_cleanup_push.3:297
2882 " printf(\"Canceling thread\\en\");\n"
2883 " s = pthread_cancel(thr);\n"
2885 " handle_error_en(s, \"pthread_cancel\");\n"
2890 #: build/C/man3/pthread_cleanup_push.3:308
2893 " if (res == PTHREAD_CANCELED)\n"
2894 " printf(\"Thread was canceled; cnt = %d\\en\", cnt);\n"
2896 " printf(\"Thread terminated normally; cnt = %d\\en\", cnt);\n"
2897 " exit(EXIT_SUCCESS);\n"
2902 #: build/C/man3/pthread_cleanup_push.3:314
2904 "B<pthread_cancel>(3), B<pthread_cleanup_push_defer_np>(3), "
2905 "B<pthread_setcancelstate>(3), B<pthread_testcancel>(3), B<pthreads>(7)"
2909 #: build/C/man3/pthread_cleanup_push_defer_np.3:24
2911 msgid "PTHREAD_CLEANUP_PUSH_DEFER_NP"
2915 #: build/C/man3/pthread_cleanup_push_defer_np.3:24
2921 #: build/C/man3/pthread_cleanup_push_defer_np.3:28
2923 "pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np - push and pop "
2924 "thread cancellation clean-up handlers while saving cancelability type"
2928 #: build/C/man3/pthread_cleanup_push_defer_np.3:35
2931 "B<void pthread_cleanup_push_defer_np(void (*>I<routine>B<)(void *),>\n"
2932 "B< void *>I<arg>B<);>\n"
2933 "B<void pthread_cleanup_pop_restore_np(int >I<execute>B<);>\n"
2937 #: build/C/man3/pthread_cleanup_push_defer_np.3:38 build/C/man3/pthread_create.3:36 build/C/man3/pthread_detach.3:35 build/C/man3/pthread_join.3:35 build/C/man3/pthread_kill.3:35 build/C/man3/pthread_sigmask.3:36 build/C/man3/pthread_sigqueue.3:35 build/C/man3/pthread_tryjoin_np.3:40 build/C/man3/pthread_yield.3:34
2938 msgid "Compile and link with I<-pthread>."
2942 #: build/C/man3/pthread_cleanup_push_defer_np.3:44
2944 "These functions are the same as B<pthread_cleanup_push>(3) and "
2945 "B<pthread_cleanup_pop>(3), except for the differences noted on this page."
2949 #: build/C/man3/pthread_cleanup_push_defer_np.3:57
2951 "Like B<pthread_cleanup_push>(3), B<pthread_cleanup_push_defer_np>() pushes "
2952 "I<routine> onto the thread's stack of cancellation clean-up handlers. In "
2953 "addition, it also saves the thread's current cancelability type, and sets "
2954 "the cancelability type to \"deferred\" (see B<pthread_setcanceltype>(3)); "
2955 "this ensures that cancellation clean-up will occur even if the thread's "
2956 "cancelability type was \"asynchronous\" before the call."
2960 #: build/C/man3/pthread_cleanup_push_defer_np.3:66
2962 "Like B<pthread_cleanup_pop>(3), B<pthread_cleanup_pop_restore_np>() pops "
2963 "the top-most clean-up handler from the thread's stack of cancellation "
2964 "clean-up handlers. In addition, it restores the thread's cancelability type "
2965 "to its value at the time of the matching B<pthread_cleanup_push_defer_np>()."
2969 #: build/C/man3/pthread_cleanup_push_defer_np.3:72
2971 "The caller must ensure that calls to these functions are paired within the "
2972 "same function, and at the same lexical nesting level. Other restrictions "
2973 "apply, as described in B<pthread_cleanup_push>(3)."
2977 #: build/C/man3/pthread_cleanup_push_defer_np.3:74
2978 msgid "This sequence of calls:"
2982 #: build/C/man3/pthread_cleanup_push_defer_np.3:79
2985 "pthread_cleanup_push_defer_np(routine, arg);\n"
2986 "pthread_cleanup_pop_restore_np(execute);\n"
2990 #: build/C/man3/pthread_cleanup_push_defer_np.3:83
2991 msgid "is equivalent to (but shorter and more efficient than):"
2995 #: build/C/man3/pthread_cleanup_push_defer_np.3:89
2997 msgid "int oldtype;\n"
3001 #: build/C/man3/pthread_cleanup_push_defer_np.3:95
3004 "pthread_cleanup_push(routine, arg);\n"
3005 "pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);\n"
3007 "pthread_setcanceltype(oldtype, NULL);\n"
3008 "pthread_cleanup_pop(execute);\n"
3012 #: build/C/man3/pthread_cleanup_push_defer_np.3:107
3014 "B<pthread_cancel>(3), B<pthread_cleanup_push>(3), "
3015 "B<pthread_setcancelstate>(3), B<pthread_testcancel>(3), B<pthreads>(7)"
3019 #: build/C/man3/pthread_create.3:24
3021 msgid "PTHREAD_CREATE"
3025 #: build/C/man3/pthread_create.3:27
3026 msgid "pthread_create - create a new thread"
3030 #: build/C/man3/pthread_create.3:33
3033 "B<int pthread_create(pthread_t *>I<thread>B<, const pthread_attr_t "
3035 "B< void *(*>I<start_routine>B<) (void *), void "
3040 #: build/C/man3/pthread_create.3:45
3042 "The B<pthread_create>() function starts a new thread in the calling "
3043 "process. The new thread starts execution by invoking I<start_routine>(); "
3044 "I<arg> is passed as the sole argument of I<start_routine>()."
3048 #: build/C/man3/pthread_create.3:47
3049 msgid "The new thread terminates in one of the following ways:"
3053 #: build/C/man3/pthread_create.3:47 build/C/man3/pthread_create.3:53 build/C/man3/pthread_create.3:61 build/C/man3/pthread_create.3:64 build/C/man3/pthread_getattr_np.3:50 build/C/man3/pthread_getattr_np.3:53 build/C/man3/pthread_getattr_np.3:56
3059 #: build/C/man3/pthread_create.3:53
3061 "It calls B<pthread_exit>(3), specifying an exit status value that is "
3062 "available to another thread in the same process that calls "
3063 "B<pthread_join>(3)."
3067 #: build/C/man3/pthread_create.3:61
3069 "It returns from I<start_routine>(). This is equivalent to calling "
3070 "B<pthread_exit>(3) with the value supplied in the I<return> statement."
3074 #: build/C/man3/pthread_create.3:64
3075 msgid "It is canceled (see B<pthread_cancel>(3))."
3079 #: build/C/man3/pthread_create.3:70
3081 "Any of the threads in the process calls B<exit>(3), or the main thread "
3082 "performs a return from I<main>(). This causes the termination of all "
3083 "threads in the process."
3087 #: build/C/man3/pthread_create.3:84
3089 "The I<attr> argument points to a I<pthread_attr_t> structure whose contents "
3090 "are used at thread creation time to determine attributes for the new thread; "
3091 "this structure is initialized using B<pthread_attr_init>(3) and related "
3092 "functions. If I<attr> is NULL, then the thread is created with default "
3097 #: build/C/man3/pthread_create.3:91
3099 "Before returning, a successful call to B<pthread_create>() stores the ID of "
3100 "the new thread in the buffer pointed to by I<thread>; this identifier is "
3101 "used to refer to the thread in subsequent calls to other pthreads functions."
3105 #: build/C/man3/pthread_create.3:99
3107 "The new thread inherits a copy of the creating thread's signal mask "
3108 "(B<pthread_sigmask>(3)). The set of pending signals for the new thread is "
3109 "empty (B<sigpending>(2)). The new thread does not inherit the creating "
3110 "thread's alternate signal stack (B<sigaltstack>(2))."
3114 #: build/C/man3/pthread_create.3:102
3116 "The new thread inherits the calling thread's floating-point environment "
3120 #. CLOCK_THREAD_CPUTIME_ID in clock_gettime(2)
3122 #: build/C/man3/pthread_create.3:107
3124 "The initial value of the new thread's CPU-time clock is 0 (see "
3125 "B<pthread_getcpuclockid>(3))."
3129 #: build/C/man3/pthread_create.3:107
3131 msgid "Linux-specific details"
3135 #: build/C/man3/pthread_create.3:113
3137 "The new thread inherits copies of the calling thread's capability sets (see "
3138 "B<capabilities>(7)) and CPU affinity mask (see B<sched_setaffinity>(2))."
3142 #: build/C/man3/pthread_create.3:120
3144 "On success, B<pthread_create>() returns 0; on error, it returns an error "
3145 "number, and the contents of I<*thread> are undefined."
3149 #: build/C/man3/pthread_create.3:121 build/C/man3/pthread_sigqueue.3:69
3155 #: build/C/man3/pthread_create.3:135
3157 "Insufficient resources to create another thread, or a system-imposed limit "
3158 "on the number of threads was encountered. The latter case may occur in two "
3159 "ways: the B<RLIMIT_NPROC> soft resource limit (set via B<setrlimit>(2)), "
3160 "which limits the number of process for a real user ID, was reached; or the "
3161 "kernel's system-wide limit on the number of threads, "
3162 "I</proc/sys/kernel/threads-max>, was reached."
3166 #: build/C/man3/pthread_create.3:139
3167 msgid "Invalid settings in I<attr>."
3171 #: build/C/man3/pthread_create.3:139 build/C/man3/pthread_setschedparam.3:127 build/C/man3/pthread_setschedprio.3:64
3177 #: build/C/man3/pthread_create.3:144
3179 "No permission to set the scheduling policy and parameters specified in "
3184 #: build/C/man3/pthread_create.3:158
3186 "See B<pthread_self>(3) for further information on the thread ID returned in "
3187 "I<*thread> by B<pthread_create>(). Unless real-time scheduling policies are "
3188 "being employed, after a call to B<pthread_create>(), it is indeterminate "
3189 "which thread\\(emthe caller or the new thread\\(emwill next execute."
3193 #: build/C/man3/pthread_create.3:178
3195 "A thread may either be I<joinable> or I<detached>. If a thread is joinable, "
3196 "then another thread can call B<pthread_join>(3) to wait for the thread to "
3197 "terminate and fetch its exit status. Only when a terminated joinable thread "
3198 "has been joined are the last of its resources released back to the system. "
3199 "When a detached thread terminates, its resources are automatically released "
3200 "back to the system: it is not possible to join with the thread in order to "
3201 "obtain its exit status. Making a thread detached is useful for some types "
3202 "of daemon threads whose exit status the application does not need to care "
3203 "about. By default, a new thread is created in a joinable state, unless "
3204 "I<attr> was set to create the thread in a detached state (using "
3205 "B<pthread_attr_setdetachstate>(3))."
3208 #. FIXME . Perhaps some of the following detail should be in
3209 #. a future pthread_attr_setstacksize(3) page.
3211 #: build/C/man3/pthread_create.3:194
3213 "On Linux/x86-32, the default stack size for a new thread is 2 megabytes. "
3214 "Under the NPTL threading implementation, if the B<RLIMIT_STACK> soft "
3215 "resource limit I<at the time the program started> has any value other than "
3216 "\"unlimited\", then it determines the default stack size of new threads. "
3217 "Using B<pthread_attr_setstacksize>(3), the stack size attribute can be "
3218 "explicitly set in the I<attr> argument used to create a thread, in order to "
3219 "obtain a stack size other than the default."
3223 #: build/C/man3/pthread_create.3:200
3225 "In the obsolete LinuxThreads implementation, each of the threads in a "
3226 "process has a different process ID. This is in violation of the POSIX "
3227 "threads specification, and is the source of many other nonconformances to "
3228 "the standard; see B<pthreads>(7)."
3232 #: build/C/man3/pthread_create.3:204
3234 "The program below demonstrates the use of B<pthread_create>(), as well as a "
3235 "number of other functions in the pthreads API."
3239 #: build/C/man3/pthread_create.3:209
3241 "In the following run, on a system providing the NPTL threading "
3242 "implementation, the stack size defaults to the value given by the \"stack "
3243 "size\" resource limit:"
3247 #: build/C/man3/pthread_create.3:221
3251 "8192 # The stack size limit is 8 MB (0x80000 bytes)\n"
3252 "$B< ./a.out hola salut servus>\n"
3253 "Thread 1: top of stack near 0xb7dd03b8; argv_string=hola\n"
3254 "Thread 2: top of stack near 0xb75cf3b8; argv_string=salut\n"
3255 "Thread 3: top of stack near 0xb6dce3b8; argv_string=servus\n"
3256 "Joined with thread 1; returned value was HOLA\n"
3257 "Joined with thread 2; returned value was SALUT\n"
3258 "Joined with thread 3; returned value was SERVUS\n"
3262 #: build/C/man3/pthread_create.3:227
3264 "In the next run, the program explicitly sets a stack size of 1MB (using "
3265 "B<pthread_attr_setstacksize>(3)) for the created threads:"
3269 #: build/C/man3/pthread_create.3:237
3272 "$B< ./a.out -s 0x100000 hola salut servus>\n"
3273 "Thread 1: top of stack near 0xb7d723b8; argv_string=hola\n"
3274 "Thread 2: top of stack near 0xb7c713b8; argv_string=salut\n"
3275 "Thread 3: top of stack near 0xb7b703b8; argv_string=servus\n"
3276 "Joined with thread 1; returned value was HOLA\n"
3277 "Joined with thread 2; returned value was SALUT\n"
3278 "Joined with thread 3; returned value was SERVUS\n"
3282 #: build/C/man3/pthread_create.3:249
3285 "#include E<lt>pthread.hE<gt>\n"
3286 "#include E<lt>string.hE<gt>\n"
3287 "#include E<lt>stdio.hE<gt>\n"
3288 "#include E<lt>stdlib.hE<gt>\n"
3289 "#include E<lt>unistd.hE<gt>\n"
3290 "#include E<lt>errno.hE<gt>\n"
3291 "#include E<lt>ctype.hE<gt>\n"
3295 #: build/C/man3/pthread_create.3:255 build/C/man3/pthread_getcpuclockid.3:108
3298 "#define handle_error(msg) \\e\n"
3299 " do { perror(msg); exit(EXIT_FAILURE); } while (0)\n"
3303 #: build/C/man3/pthread_create.3:261
3306 "struct thread_info { /* Used as argument to thread_start() */\n"
3307 " pthread_t thread_id; /* ID returned by pthread_create() */\n"
3308 " int thread_num; /* Application-defined thread # */\n"
3309 " char *argv_string; /* From command-line argument */\n"
3314 #: build/C/man3/pthread_create.3:264
3317 "/* Thread start function: display address near top of our stack,\n"
3318 " and return upper-cased copy of argv_string */\n"
3322 #: build/C/man3/pthread_create.3:270
3326 "thread_start(void *arg)\n"
3328 " struct thread_info *tinfo = (struct thread_info *) arg;\n"
3329 " char *uargv, *p;\n"
3333 #: build/C/man3/pthread_create.3:273
3336 " printf(\"Thread %d: top of stack near %p; argv_string=%s\\en\",\n"
3337 " tinfo-E<gt>thread_num, &p, tinfo-E<gt>argv_string);\n"
3341 #: build/C/man3/pthread_create.3:277
3344 " uargv = strdup(tinfo-E<gt>argv_string);\n"
3345 " if (uargv == NULL)\n"
3346 " handle_error(\"strdup\");\n"
3350 #: build/C/man3/pthread_create.3:280
3353 " for (p = uargv; *p != \\(aq\\e0\\(aq; p++)\n"
3354 " *p = toupper(*p);\n"
3358 #: build/C/man3/pthread_create.3:283
3366 #: build/C/man3/pthread_create.3:292
3370 "main(int argc, char *argv[])\n"
3372 " int s, tnum, opt, num_threads;\n"
3373 " struct thread_info *tinfo;\n"
3374 " pthread_attr_t attr;\n"
3375 " int stack_size;\n"
3380 #: build/C/man3/pthread_create.3:294
3382 msgid " /* The \"-s\" option specifies a stack size for our threads */\n"
3386 #: build/C/man3/pthread_create.3:301
3389 " stack_size = -1;\n"
3390 " while ((opt = getopt(argc, argv, \"s:\")) != -1) {\n"
3392 " case \\(aqs\\(aq:\n"
3393 " stack_size = strtoul(optarg, NULL, 0);\n"
3398 #: build/C/man3/pthread_create.3:308
3402 " fprintf(stderr, \"Usage: %s [-s stack-size] arg...\\en\",\n"
3404 " exit(EXIT_FAILURE);\n"
3410 #: build/C/man3/pthread_create.3:310
3412 msgid " num_threads = argc - optind;\n"
3416 #: build/C/man3/pthread_create.3:312
3418 msgid " /* Initialize thread creation attributes */\n"
3422 #: build/C/man3/pthread_create.3:316
3425 " s = pthread_attr_init(&attr);\n"
3427 " handle_error_en(s, \"pthread_attr_init\");\n"
3431 #: build/C/man3/pthread_create.3:322
3434 " if (stack_size E<gt> 0) {\n"
3435 " s = pthread_attr_setstacksize(&attr, stack_size);\n"
3437 " handle_error_en(s, \"pthread_attr_setstacksize\");\n"
3442 #: build/C/man3/pthread_create.3:324
3444 msgid " /* Allocate memory for pthread_create() arguments */\n"
3448 #: build/C/man3/pthread_create.3:328
3451 " tinfo = calloc(num_threads, sizeof(struct thread_info));\n"
3452 " if (tinfo == NULL)\n"
3453 " handle_error(\"calloc\");\n"
3457 #: build/C/man3/pthread_create.3:330
3459 msgid " /* Create one thread for each command-line argument */\n"
3463 #: build/C/man3/pthread_create.3:334
3466 " for (tnum = 0; tnum E<lt> num_threads; tnum++) {\n"
3467 " tinfo[tnum].thread_num = tnum + 1;\n"
3468 " tinfo[tnum].argv_string = argv[optind + tnum];\n"
3472 #: build/C/man3/pthread_create.3:337
3475 " /* The pthread_create() call stores the thread ID into\n"
3476 " corresponding element of tinfo[] */\n"
3480 #: build/C/man3/pthread_create.3:343
3483 " s = pthread_create(&tinfo[tnum].thread_id, &attr,\n"
3484 " &thread_start, &tinfo[tnum]);\n"
3486 " handle_error_en(s, \"pthread_create\");\n"
3491 #: build/C/man3/pthread_create.3:346
3494 " /* Destroy the thread attributes object, since it is no\n"
3495 " longer needed */\n"
3499 #: build/C/man3/pthread_create.3:350 build/C/man3/pthread_setschedparam.3:421
3502 " s = pthread_attr_destroy(&attr);\n"
3504 " handle_error_en(s, \"pthread_attr_destroy\");\n"
3508 #: build/C/man3/pthread_create.3:352
3510 msgid " /* Now join with each thread, and display its returned value */\n"
3514 #: build/C/man3/pthread_create.3:357
3517 " for (tnum = 0; tnum E<lt> num_threads; tnum++) {\n"
3518 " s = pthread_join(tinfo[tnum].thread_id, &res);\n"
3520 " handle_error_en(s, \"pthread_join\");\n"
3524 #: build/C/man3/pthread_create.3:362
3527 " printf(\"Joined with thread %d; returned value was %s\\en\",\n"
3528 " tinfo[tnum].thread_num, (char *) res);\n"
3529 " free(res); /* Free memory allocated by thread */\n"
3534 #: build/C/man3/pthread_create.3:366
3538 " exit(EXIT_SUCCESS);\n"
3543 #: build/C/man3/pthread_create.3:377
3545 "B<getrlimit>(2), B<pthread_attr_init>(3), B<pthread_cancel>(3), "
3546 "B<pthread_detach>(3), B<pthread_equal>(3), B<pthread_exit>(3), "
3547 "B<pthread_getattr_np>(3), B<pthread_join>(3), B<pthread_self>(3), "
3552 #: build/C/man3/pthread_detach.3:24
3554 msgid "PTHREAD_DETACH"
3558 #: build/C/man3/pthread_detach.3:24 build/C/man3/pthread_join.3:24
3564 #: build/C/man3/pthread_detach.3:27
3565 msgid "pthread_detach - detach a thread"
3569 #: build/C/man3/pthread_detach.3:32
3571 msgid "B<int pthread_detach(pthread_t >I<thread>B<);>\n"
3575 #: build/C/man3/pthread_detach.3:44
3577 "The B<pthread_detach>() function marks the thread identified by I<thread> "
3578 "as detached. When a detached thread terminates, its resources are "
3579 "automatically released back to the system without the need for another "
3580 "thread to join with the terminated thread."
3584 #: build/C/man3/pthread_detach.3:47
3586 "Attempting to detach an already detached thread results in unspecified "
3591 #: build/C/man3/pthread_detach.3:52
3593 "On success, B<pthread_detach>() returns 0; on error, it returns an error "
3598 #: build/C/man3/pthread_detach.3:57 build/C/man3/pthread_join.3:87
3599 msgid "I<thread> is not a joinable thread."
3603 #: build/C/man3/pthread_detach.3:68
3605 "Once a thread has been detached, it can't be joined with B<pthread_join>(3) "
3606 "or be made joinable again."
3610 #: build/C/man3/pthread_detach.3:75
3612 "A new thread can be created in a detached state using "
3613 "B<pthread_attr_setdetachstate>(3) to set the detached attribute of the "
3614 "I<attr> argument of B<pthread_create>(3)."
3618 #: build/C/man3/pthread_detach.3:82
3620 "The detached attribute merely determines the behavior of the system when the "
3621 "thread terminates; it does not prevent the thread from being terminated if "
3622 "the process terminates using B<exit>(3) (or equivalently, if the main "
3627 #: build/C/man3/pthread_detach.3:91
3629 "Either B<pthread_join>(3) or B<pthread_detach>() should be called for each "
3630 "thread that an application creates, so that system resources for the thread "
3631 "can be released. (But note that the resources of all threads are freed when "
3632 "the process terminates.)"
3636 #: build/C/man3/pthread_detach.3:93
3637 msgid "The following statement detaches the calling thread:"
3641 #: build/C/man3/pthread_detach.3:95
3643 msgid " pthread_detach(pthread_self());\n"
3647 #: build/C/man3/pthread_detach.3:101
3649 "B<pthread_attr_setdetachstate>(3), B<pthread_cancel>(3), "
3650 "B<pthread_create>(3), B<pthread_exit>(3), B<pthread_join>(3), B<pthreads>(7)"
3654 #: build/C/man3/pthread_equal.3:24
3656 msgid "PTHREAD_EQUAL"
3660 #: build/C/man3/pthread_equal.3:24 build/C/man3/pthread_exit.3:24
3666 #: build/C/man3/pthread_equal.3:27
3667 msgid "pthread_equal - compare thread IDs"
3671 #: build/C/man3/pthread_equal.3:32
3673 msgid "B<int pthread_equal(pthread_t >I<t1>B<, pthread_t >I<t2>B<);>\n"
3677 #: build/C/man3/pthread_equal.3:39
3678 msgid "The B<pthread_equal>() function compares two thread identifiers."
3682 #: build/C/man3/pthread_equal.3:43
3684 "If the two thread IDs are equal, B<pthread_equal>() returns a nonzero "
3685 "value; otherwise, it returns 0."
3689 #. Available since glibc 2.0
3691 #: build/C/man3/pthread_equal.3:45 build/C/man3/pthread_exit.3:73 build/C/man3/pthread_self.3:48 build/C/man3/pthread_testcancel.3:56
3692 msgid "This function always succeeds."
3696 #: build/C/man3/pthread_equal.3:54
3698 "The B<pthread_equal>() function is necessary because thread IDs should be "
3699 "considered opaque: there is no portable way for applications to directly "
3700 "compare two I<pthread_t> values."
3704 #: build/C/man3/pthread_equal.3:57
3705 msgid "B<pthread_create>(3), B<pthread_self>(3), B<pthreads>(7)"
3709 #: build/C/man3/pthread_exit.3:24
3711 msgid "PTHREAD_EXIT"
3715 #: build/C/man3/pthread_exit.3:27
3716 msgid "pthread_exit - terminate calling thread"
3720 #: build/C/man3/pthread_exit.3:32
3722 msgid "B<void pthread_exit(void *>I<retval>B<);>\n"
3726 #: build/C/man3/pthread_exit.3:43
3728 "The B<pthread_exit>() function terminates the calling thread and returns a "
3729 "value via I<retval> that (if the thread is joinable) is available to "
3730 "another thread in the same process that calls B<pthread_join>(3)."
3734 #: build/C/man3/pthread_exit.3:53
3736 "Any clean-up handlers established by B<pthread_cleanup_push>(3) that have "
3737 "not yet been popped, are popped (in the reverse of the order in which they "
3738 "were pushed) and executed. If the thread has any thread-specific data, "
3739 "then, after the clean-up handlers have been executed, the corresponding "
3740 "destructor functions are called, in an unspecified order."
3744 #: build/C/man3/pthread_exit.3:60
3746 "When a thread terminates, process-shared resources (e.g., mutexes, condition "
3747 "variables, semaphores, and file descriptors) are not released, and functions "
3748 "registered using B<atexit>(3) are not called."
3752 #: build/C/man3/pthread_exit.3:69
3754 "After the last thread in a process terminates, the process terminates as by "
3755 "calling B<exit>(3) with an exit status of zero; thus, process-shared "
3756 "resources are released and functions registered using B<atexit>(3) are "
3761 #: build/C/man3/pthread_exit.3:71
3762 msgid "This function does not return to the caller."
3766 #: build/C/man3/pthread_exit.3:80
3768 "Performing a return from the start function of any thread other than the "
3769 "main thread results in an implicit call to B<pthread_exit>(), using the "
3770 "function's return value as the thread's exit status."
3774 #: build/C/man3/pthread_exit.3:86
3776 "To allow other threads to continue execution, the main thread should "
3777 "terminate by calling B<pthread_exit>() rather than B<exit>(3)."
3781 #: build/C/man3/pthread_exit.3:91
3783 "The value pointed to by I<retval> should not be located on the calling "
3784 "thread's stack, since the contents of that stack are undefined after the "
3785 "thread terminates."
3789 #. FIXME . review a later kernel to see if this gets fixed
3790 #. http://thread.gmane.org/gmane.linux.kernel/611611
3791 #. http://marc.info/?l=linux-kernel&m=122525468300823&w=2
3793 #: build/C/man3/pthread_exit.3:103
3795 "Currently, there are limitations in the kernel implementation logic for "
3796 "B<wait>(2)ing on a stopped thread group with a dead thread group leader. "
3797 "This can manifest in problems such as a locked terminal if a stop signal is "
3798 "sent to a foreground process whose thread group leader has already called "
3799 "B<pthread_exit>()."
3803 #: build/C/man3/pthread_exit.3:106
3804 msgid "B<pthread_create>(3), B<pthread_join>(3), B<pthreads>(7)"
3808 #: build/C/man3/pthread_getattr_np.3:24
3810 msgid "PTHREAD_GETATTR_NP"
3814 #: build/C/man3/pthread_getattr_np.3:27
3815 msgid "pthread_getattr_np - get attributes of created thread"
3819 #: build/C/man3/pthread_getattr_np.3:33
3822 "B<int pthread_getattr_np(pthread_t >I<thread>B<, pthread_attr_t "
3827 #: build/C/man3/pthread_getattr_np.3:43
3829 "The B<pthread_getattr_np>() function initializes the thread attributes "
3830 "object referred to by I<attr> so that it contains actual attribute values "
3831 "describing the running thread I<thread>."
3835 #: build/C/man3/pthread_getattr_np.3:50
3837 "The returned attribute values may differ from the corresponding attribute "
3838 "values passed in the I<attr> object that was used to create the thread using "
3839 "B<pthread_create>(3). In particular, the following attributes may differ:"
3843 #: build/C/man3/pthread_getattr_np.3:53
3845 "the detach state, since a joinable thread may have detached itself after "
3850 #: build/C/man3/pthread_getattr_np.3:56
3851 msgid "the stack size, which the implementation may align to a suitable boundary."
3855 #: build/C/man3/pthread_getattr_np.3:61
3857 "and the guard size, which the implementation may round upward to a multiple "
3858 "of the page size, or ignore (i.e., treat as 0), if the application is "
3859 "allocating its own stack."
3863 #: build/C/man3/pthread_getattr_np.3:66
3865 "Furthermore, if the stack address attribute was not set in the thread "
3866 "attributes object used to create the thread, then the returned thread "
3867 "attributes object will report the actual stack address that the "
3868 "implementation selected for the thread."
3872 #: build/C/man3/pthread_getattr_np.3:71
3874 "When the thread attributes object returned by B<pthread_getattr_np>() is no "
3875 "longer required, it should be destroyed using B<pthread_attr_destroy>(3)."
3879 #: build/C/man3/pthread_getattr_np.3:74 build/C/man3/pthread_getcpuclockid.3:47
3881 "On success, this function returns 0; on error, it returns a nonzero error "
3885 #. Can happen (but unlikely) while trying to allocate memory for cpuset
3887 #: build/C/man3/pthread_getattr_np.3:79
3888 msgid "Insufficient memory."
3892 #: build/C/man3/pthread_getattr_np.3:94
3894 "In addition, if I<thread> refers to the main thread, then "
3895 "B<pthread_getattr_np>() can fail because of errors from various underlying "
3896 "calls: B<fopen>(3), if I</proc/self/maps> can't be opened; and "
3897 "B<getrlimit>(2), if the B<RLIMIT_STACK> resource limit is not supported."
3901 #: build/C/man3/pthread_getattr_np.3:96
3902 msgid "This function is available in glibc since version 2.2.3."
3906 #: build/C/man3/pthread_getattr_np.3:99 build/C/man3/pthread_kill_other_threads_np.3:48
3908 "This function is a nonstandard GNU extension; hence the suffix \"_np\" "
3909 "(nonportable) in the name."
3913 #: build/C/man3/pthread_getattr_np.3:109
3915 "The program below demonstrates the use of B<pthread_getattr_np>(). The "
3916 "program creates a thread that then uses B<pthread_getattr_np>() to retrieve "
3917 "and display its guard size, stack address, and stack size attributes. "
3918 "Command-line arguments can be used to set these attributes to values other "
3919 "than the default when creating the thread. The shell sessions below "
3920 "demonstrate the use of the program."
3924 #: build/C/man3/pthread_getattr_np.3:112
3926 "In the first run, on an x86-32 system, a thread is created using default "
3931 #: build/C/man3/pthread_getattr_np.3:122
3934 "$B< ulimit -s> # No stack limit ==E<gt> default stack size is 2MB\n"
3937 "Attributes of created thread:\n"
3938 " Guard size = 4096 bytes\n"
3939 " Stack address = 0x40196000 (EOS = 0x40397000)\n"
3940 " Stack size = 0x201000 (2101248) bytes\n"
3944 #: build/C/man3/pthread_getattr_np.3:128
3946 "In the following run, we see that if a guard size is specified, it is "
3947 "rounded up to the next multiple of the system page size (4096 bytes on "
3952 #: build/C/man3/pthread_getattr_np.3:136
3955 "$B< ./a.out -g 4097>\n"
3956 "Thread attributes object after initializations:\n"
3957 " Guard size = 4097 bytes\n"
3958 " Stack address = (nil)\n"
3959 " Stack size = 0x0 (0) bytes\n"
3963 #: build/C/man3/pthread_getattr_np.3:141
3966 "Attributes of created thread:\n"
3967 " Guard size = 8192 bytes\n"
3968 " Stack address = 0x40196000 (EOS = 0x40397000)\n"
3969 " Stack size = 0x201000 (2101248) bytes\n"
3974 #. $ ./a.out \-s 0x8000
3975 #. Thread attributes object after initializations:
3976 #. Guard size = 4096 bytes
3977 #. Stack address = 0xffff8000 (EOS = (nil))
3978 #. Stack size = 0x8000 (32768) bytes
3980 #. Attributes of created thread:
3981 #. Guard size = 4096 bytes
3982 #. Stack address = 0x4001e000 (EOS = 0x40026000)
3983 #. Stack size = 0x8000 (32768) bytes
3987 #: build/C/man3/pthread_getattr_np.3:160
3989 "In the last run, the program manually allocates a stack for the thread. In "
3990 "this case, the guard size attribute is ignored."
3994 #: build/C/man3/pthread_getattr_np.3:165
3997 "$B< ./a.out -g 4096 -s 0x8000 -a>\n"
3998 "Allocated thread stack at 0x804d000\n"
4002 #: build/C/man3/pthread_getattr_np.3:170
4005 "Thread attributes object after initializations:\n"
4006 " Guard size = 4096 bytes\n"
4007 " Stack address = 0x804d000 (EOS = 0x8055000)\n"
4008 " Stack size = 0x8000 (32768) bytes\n"
4012 #: build/C/man3/pthread_getattr_np.3:175
4015 "Attributes of created thread:\n"
4016 " Guard size = 0 bytes\n"
4017 " Stack address = 0x804d000 (EOS = 0x8055000)\n"
4018 " Stack size = 0x8000 (32768) bytes\n"
4022 #: build/C/man3/pthread_getattr_np.3:196
4026 "display_stack_related_attributes(pthread_attr_t *attr, char *prefix)\n"
4029 " size_t stack_size, guard_size;\n"
4030 " void *stack_addr;\n"
4034 #: build/C/man3/pthread_getattr_np.3:201
4037 " s = pthread_attr_getguardsize(attr, &guard_size);\n"
4039 " handle_error_en(s, \"pthread_attr_getguardsize\");\n"
4040 " printf(\"%sGuard size = %d bytes\\en\", prefix, guard_size);\n"
4044 #: build/C/man3/pthread_getattr_np.3:212
4047 " s = pthread_attr_getstack(attr, &stack_addr, &stack_size);\n"
4049 " handle_error_en(s, \"pthread_attr_getstack\");\n"
4050 " printf(\"%sStack address = %p\", prefix, stack_addr);\n"
4051 " if (stack_size E<gt> 0)\n"
4052 " printf(\" (EOS = %p)\", (char *) stack_addr + stack_size);\n"
4053 " printf(\"\\en\");\n"
4054 " printf(\"%sStack size = 0x%x (%d) bytes\\en\",\n"
4055 " prefix, stack_size, stack_size);\n"
4060 #: build/C/man3/pthread_getattr_np.3:218
4064 "display_thread_attributes(pthread_t thread, char *prefix)\n"
4067 " pthread_attr_t attr;\n"
4071 #: build/C/man3/pthread_getattr_np.3:222
4074 " s = pthread_getattr_np(thread, &attr);\n"
4076 " handle_error_en(s, \"pthread_getattr_np\");\n"
4080 #: build/C/man3/pthread_getattr_np.3:224
4082 msgid " display_stack_related_attributes(&attr, prefix);\n"
4086 #: build/C/man3/pthread_getattr_np.3:229
4089 " s = pthread_attr_destroy(&attr);\n"
4091 " handle_error_en(s, \"pthread_attr_destroy\");\n"
4096 #: build/C/man3/pthread_getattr_np.3:235
4099 "static void * /* Start function for thread we create */\n"
4100 "thread_start(void *arg)\n"
4102 " printf(\"Attributes of created thread:\\en\");\n"
4103 " display_thread_attributes(pthread_self(), \"\\et\");\n"
4107 #: build/C/man3/pthread_getattr_np.3:249
4111 "usage(char *pname, char *msg)\n"
4113 " if (msg != NULL)\n"
4114 " fputs(msg, stderr);\n"
4115 " fprintf(stderr, \"Usage: %s [-s stack-size [-a]]\"\n"
4116 " \" [-g guard-size]\\en\", pname);\n"
4117 " fprintf(stderr, \"\\et\\et-a means program should allocate "
4119 " exit(EXIT_FAILURE);\n"
4124 #: build/C/man3/pthread_getattr_np.3:262
4127 "static pthread_attr_t * /* Get thread attributes from command line */\n"
4128 "get_thread_attributes_from_cl(int argc, char *argv[],\n"
4129 " pthread_attr_t *attrp)\n"
4131 " int s, opt, allocate_stack;\n"
4132 " long stack_size, guard_size;\n"
4133 " void *stack_addr;\n"
4134 " pthread_attr_t *ret_attrp = NULL; /* Set to attrp if we initialize\n"
4135 " a thread attributes object */\n"
4136 " allocate_stack = 0;\n"
4137 " stack_size = -1;\n"
4138 " guard_size = -1;\n"
4142 #: build/C/man3/pthread_getattr_np.3:271
4145 " while ((opt = getopt(argc, argv, \"ag:s:\")) != -1) {\n"
4147 " case \\(aqa\\(aq: allocate_stack = 1; break;\n"
4148 " case \\(aqg\\(aq: guard_size = strtoul(optarg, NULL, 0); break;\n"
4149 " case \\(aqs\\(aq: stack_size = strtoul(optarg, NULL, 0); break;\n"
4150 " default: usage(argv[0], NULL);\n"
4156 #: build/C/man3/pthread_getattr_np.3:274
4159 " if (allocate_stack && stack_size == -1)\n"
4160 " usage(argv[0], \"Specifying -a without -s makes no sense\\en\");\n"
4164 #: build/C/man3/pthread_getattr_np.3:277
4167 " if (argc E<gt> optind)\n"
4168 " usage(argv[0], \"Extraneous command-line arguments\\en\");\n"
4172 #: build/C/man3/pthread_getattr_np.3:280
4175 " if (stack_size E<gt>= 0 || guard_size E<gt> 0) {\n"
4176 " ret_attrp = attrp;\n"
4180 #: build/C/man3/pthread_getattr_np.3:285
4183 " s = pthread_attr_init(attrp);\n"
4185 " handle_error_en(s, \"pthread_attr_init\");\n"
4190 #: build/C/man3/pthread_getattr_np.3:297
4193 " if (stack_size E<gt>= 0) {\n"
4194 " if (!allocate_stack) {\n"
4195 " s = pthread_attr_setstacksize(attrp, stack_size);\n"
4197 " handle_error_en(s, \"pthread_attr_setstacksize\");\n"
4199 " s = posix_memalign(&stack_addr, sysconf(_SC_PAGESIZE),\n"
4202 " handle_error_en(s, \"posix_memalign\");\n"
4203 " printf(\"Allocated thread stack at %p\\en\\en\", stack_addr);\n"
4207 #: build/C/man3/pthread_getattr_np.3:303
4210 " s = pthread_attr_setstack(attrp, stack_addr, stack_size);\n"
4212 " handle_error_en(s, \"pthread_attr_setstacksize\");\n"
4218 #: build/C/man3/pthread_getattr_np.3:309
4221 " if (guard_size E<gt>= 0) {\n"
4222 " s = pthread_attr_setguardsize(attrp, guard_size);\n"
4224 " handle_error_en(s, \"pthread_attr_setstacksize\");\n"
4229 #: build/C/man3/pthread_getattr_np.3:312
4232 " return ret_attrp;\n"
4237 #: build/C/man3/pthread_getattr_np.3:321
4241 "main(int argc, char *argv[])\n"
4245 " pthread_attr_t attr;\n"
4246 " pthread_attr_t *attrp = NULL; /* Set to &attr if we initialize\n"
4247 " a thread attributes object */\n"
4251 #: build/C/man3/pthread_getattr_np.3:323
4253 msgid " attrp = get_thread_attributes_from_cl(argc, argv, &attr);\n"
4257 #: build/C/man3/pthread_getattr_np.3:329
4260 " if (attrp != NULL) {\n"
4261 " printf(\"Thread attributes object after initializations:\\en\");\n"
4262 " display_stack_related_attributes(attrp, \"\\et\");\n"
4263 " printf(\"\\en\");\n"
4268 #: build/C/man3/pthread_getattr_np.3:356
4270 "B<pthread_attr_getaffinity_np>(3), B<pthread_attr_getdetachstate>(3), "
4271 "B<pthread_attr_getguardsize>(3), B<pthread_attr_getinheritsched>(3), "
4272 "B<pthread_attr_getschedparam>(3), B<pthread_attr_getschedpolicy>(3), "
4273 "B<pthread_attr_getscope>(3), B<pthread_attr_getstack>(3), "
4274 "B<pthread_attr_getstackaddr>(3), B<pthread_attr_getstacksize>(3), "
4275 "B<pthread_attr_init>(3), B<pthread_create>(3), B<pthreads>(7)"
4279 #: build/C/man3/pthread_getcpuclockid.3:24
4281 msgid "PTHREAD_GETCPUCLOCKID"
4285 #: build/C/man3/pthread_getcpuclockid.3:24
4291 #: build/C/man3/pthread_getcpuclockid.3:27
4292 msgid "pthread_getcpuclockid - retrieve ID of a thread's CPU time clock"
4296 #: build/C/man3/pthread_getcpuclockid.3:31
4299 "B<#include E<lt>pthread.hE<gt>>\n"
4300 "B<#include E<lt>time.hE<gt>>\n"
4304 #: build/C/man3/pthread_getcpuclockid.3:33
4307 "B<int pthread_getcpuclockid(pthread_t >I<thread>B<, clockid_t "
4311 #. The clockid is constructed as follows:
4312 #. *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE)
4313 #. where CLOCK_IDFIELD_SIZE is 3.
4315 #: build/C/man3/pthread_getcpuclockid.3:44
4317 "The B<pthread_getcpuclockid>() function returns the clock ID for the CPU "
4318 "time clock of the thread I<thread>."
4322 #: build/C/man3/pthread_getcpuclockid.3:48
4327 #. CLOCK_THREAD_CPUTIME_ID not defined
4329 #. Looking at nptl/pthread_getcpuclockid.c an ERANGE error would
4330 #. be possible if kernel thread IDs took more than 29 bits (which
4331 #. they currently cannot).
4333 #: build/C/man3/pthread_getcpuclockid.3:56
4334 msgid "Per-thread CPU time clocks are not supported by the system."
4338 #: build/C/man3/pthread_getcpuclockid.3:63
4339 msgid "This function is available in glibc since version 2.2."
4343 #: build/C/man3/pthread_getcpuclockid.3:76
4345 "When I<thread> refers to the calling thread, this function returns an "
4346 "identifier that refers to the same clock manipulated by B<clock_gettime>(2) "
4347 "and B<clock_settime>(2) when given the clock ID B<CLOCK_THREAD_CPUTIME_ID>."
4351 #: build/C/man3/pthread_getcpuclockid.3:82
4353 "The program below creates a thread and then uses B<clock_gettime>(2) to "
4354 "retrieve the total process CPU time, and the per-thread CPU time consumed by "
4355 "the two threads. The following shell session shows an example run:"
4359 #: build/C/man3/pthread_getcpuclockid.3:91
4363 "Main thread sleeping\n"
4364 "Subthread starting infinite loop\n"
4365 "Main thread consuming some CPU time...\n"
4366 "Process total CPU time: 1.368\n"
4367 "Main thread CPU time: 0.376\n"
4368 "Subthread CPU time: 0.992\n"
4372 #: build/C/man3/pthread_getcpuclockid.3:97
4374 msgid "/* Link with \"-lrt\" */\n"
4378 #: build/C/man3/pthread_getcpuclockid.3:105
4381 "#include E<lt>time.hE<gt>\n"
4382 "#include E<lt>stdio.hE<gt>\n"
4383 "#include E<lt>stdlib.hE<gt>\n"
4384 "#include E<lt>unistd.hE<gt>\n"
4385 "#include E<lt>pthread.hE<gt>\n"
4386 "#include E<lt>string.hE<gt>\n"
4387 "#include E<lt>errno.hE<gt>\n"
4391 #: build/C/man3/pthread_getcpuclockid.3:119
4395 "thread_start(void *arg)\n"
4397 " printf(\"Subthread starting infinite loop\\en\");\n"
4404 #: build/C/man3/pthread_getcpuclockid.3:124
4408 "pclock(char *msg, clockid_t cid)\n"
4410 " struct timespec ts;\n"
4414 #: build/C/man3/pthread_getcpuclockid.3:130
4417 " printf(\"%s\", msg);\n"
4418 " if (clock_gettime(cid, &ts) == -1)\n"
4419 " handle_error(\"clock_gettime\");\n"
4420 " printf(\"%4ld.%03ld\\en\", ts.tv_sec, ts.tv_nsec / 1000000);\n"
4425 #: build/C/man3/pthread_getcpuclockid.3:137
4429 "main(int argc, char *argv[])\n"
4431 " pthread_t thread;\n"
4437 #: build/C/man3/pthread_getcpuclockid.3:141
4440 " s = pthread_create(&thread, NULL, thread_start, NULL);\n"
4442 " handle_error_en(s, \"pthread_create\");\n"
4446 #: build/C/man3/pthread_getcpuclockid.3:144
4449 " printf(\"Main thread sleeping\\en\");\n"
4454 #: build/C/man3/pthread_getcpuclockid.3:148
4457 " printf(\"Main thread consuming some CPU time...\\en\");\n"
4458 " for (j = 0; j E<lt> 2000000; j++)\n"
4463 #: build/C/man3/pthread_getcpuclockid.3:150
4465 msgid " pclock(\"Process total CPU time: \", CLOCK_PROCESS_CPUTIME_ID);\n"
4469 #: build/C/man3/pthread_getcpuclockid.3:155
4472 " s = pthread_getcpuclockid(pthread_self(), &cid);\n"
4474 " handle_error_en(s, \"pthread_getcpuclockid\");\n"
4475 " pclock(\"Main thread CPU time: \", cid);\n"
4479 #: build/C/man3/pthread_getcpuclockid.3:158
4482 " /* The preceding 4 lines of code could have been replaced by:\n"
4483 " pclock(\"Main thread CPU time: \", CLOCK_THREAD_CPUTIME_ID); */\n"
4487 #: build/C/man3/pthread_getcpuclockid.3:163
4490 " s = pthread_getcpuclockid(thread, &cid);\n"
4492 " handle_error_en(s, \"pthread_getcpuclockid\");\n"
4493 " pclock(\"Subthread CPU time: 1 \", cid);\n"
4497 #: build/C/man3/pthread_getcpuclockid.3:166
4500 " exit(EXIT_SUCCESS); /* Terminates both threads */\n"
4505 #: build/C/man3/pthread_getcpuclockid.3:174
4507 "B<clock_gettime>(2), B<clock_settime>(2), B<timer_create>(2), "
4508 "B<clock_getcpuclockid>(3), B<pthread_self>(3), B<pthreads>(7), B<time>(7)"
4512 #: build/C/man3/pthread_join.3:24
4514 msgid "PTHREAD_JOIN"
4518 #: build/C/man3/pthread_join.3:27
4519 msgid "pthread_join - join with a terminated thread"
4523 #: build/C/man3/pthread_join.3:32
4525 msgid "B<int pthread_join(pthread_t >I<thread>B<, void **>I<retval>B<);>\n"
4529 #: build/C/man3/pthread_join.3:47
4531 "The B<pthread_join>() function waits for the thread specified by I<thread> "
4532 "to terminate. If that thread has already terminated, then B<pthread_join>() "
4533 "returns immediately. The thread specified by I<thread> must be joinable."
4537 #: build/C/man3/pthread_join.3:61
4539 "If I<retval> is not NULL, then B<pthread_join>() copies the exit status of "
4540 "the target thread (i.e., the value that the target thread supplied to "
4541 "B<pthread_exit>(3)) into the location pointed to by I<*retval>. If the "
4542 "target thread was canceled, then B<PTHREAD_CANCELED> is placed in "
4547 #: build/C/man3/pthread_join.3:68
4549 "If multiple threads simultaneously try to join with the same thread, the "
4550 "results are undefined. If the thread calling B<pthread_join>() is "
4551 "canceled, then the target thread will remain joinable (i.e., it will not be "
4556 #: build/C/man3/pthread_join.3:73
4558 "On success, B<pthread_join>() returns 0; on error, it returns an error "
4563 #: build/C/man3/pthread_join.3:74
4568 #. The following verified by testing on glibc 2.8/NPTL:
4569 #. The following verified by testing on glibc 2.8/NPTL:
4571 #: build/C/man3/pthread_join.3:83
4573 "A deadlock was detected (e.g., two threads tried to join with each other); "
4574 "or I<thread> specifies the calling thread."
4577 #. POSIX.1-2001 does not specify this error case.
4579 #: build/C/man3/pthread_join.3:91
4580 msgid "Another thread is already waiting to join with this thread."
4584 #: build/C/man3/pthread_join.3:102
4586 "After a successful call to B<pthread_join>(), the caller is guaranteed that "
4587 "the target thread has terminated."
4591 #: build/C/man3/pthread_join.3:105
4593 "Joining with a thread that has previously been joined results in undefined "
4598 #: build/C/man3/pthread_join.3:113
4600 "Failure to join with a thread that is joinable (i.e., one that is not "
4601 "detached), produces a \"zombie thread\". Avoid doing this, since each "
4602 "zombie thread consumes some system resources, and when enough zombie threads "
4603 "have accumulated, it will no longer be possible to create new threads (or "
4608 #: build/C/man3/pthread_join.3:119
4610 "There is no pthreads analog of I<waitpid(-1,\\ &status,\\ 0)>, that is, "
4611 "\"join with any terminated thread\". If you believe you need this "
4612 "functionality, you probably need to rethink your application design."
4616 #: build/C/man3/pthread_join.3:122
4618 "All of the threads in a process are peers: any thread can join with any "
4619 "other thread in the process."
4623 #: build/C/man3/pthread_join.3:131
4625 "B<pthread_cancel>(3), B<pthread_create>(3), B<pthread_detach>(3), "
4626 "B<pthread_exit>(3), B<pthread_tryjoin_np>(3), B<pthreads>(7)"
4630 #: build/C/man3/pthread_kill.3:24
4632 msgid "PTHREAD_KILL"
4636 #: build/C/man3/pthread_kill.3:24
4642 #: build/C/man3/pthread_kill.3:27
4643 msgid "pthread_kill - send a signal to a thread"
4647 #: build/C/man3/pthread_kill.3:30 build/C/man3/pthread_sigmask.3:30
4649 msgid "B<#include E<lt>signal.hE<gt>>\n"
4653 #: build/C/man3/pthread_kill.3:32
4655 msgid "B<int pthread_kill(pthread_t >I<thread>B<, int >I<sig>B<);>\n"
4659 #: build/C/man3/pthread_kill.3:45
4661 "The B<pthread_kill>() function sends the signal I<sig> to I<thread>, "
4662 "another thread in the same process as the caller. The signal is "
4663 "asynchronously directed to I<thread>."
4667 #: build/C/man3/pthread_kill.3:50
4669 "If I<sig> is 0, then no signal is sent, but error checking is still "
4670 "performed; this can be used to check for the existence of a thread ID."
4674 #: build/C/man3/pthread_kill.3:55
4676 "On success, B<pthread_kill>() returns 0; on error, it returns an error "
4677 "number, and no signal is sent."
4681 #: build/C/man3/pthread_kill.3:59
4682 msgid "An invalid signal was specified."
4686 #: build/C/man3/pthread_kill.3:73
4688 "Signal dispositions are process-wide: if a signal handler is installed, the "
4689 "handler will be invoked in the thread I<thread>, but if the disposition of "
4690 "the signal is \"stop\", \"continue\", or \"terminate\", this action will "
4691 "affect the whole process."
4695 #: build/C/man3/pthread_kill.3:81
4697 "B<kill>(2) B<sigaction>(2), B<sigpending>(2), B<pthread_self>(3), "
4698 "B<pthread_sigmask>(3), B<raise>(3), B<pthreads>(7), B<signal>(7)"
4702 #: build/C/man3/pthread_kill_other_threads_np.3:24
4704 msgid "PTHREAD_KILL_OTHER_THREADS_NP"
4708 #: build/C/man3/pthread_kill_other_threads_np.3:24
4714 #: build/C/man3/pthread_kill_other_threads_np.3:27
4715 msgid "pthread_kill_other_threads_np - terminate all other threads in process"
4719 #: build/C/man3/pthread_kill_other_threads_np.3:32
4721 msgid "B<void pthread_kill_other_threads_np(void);>\n"
4725 #. Available since glibc 2.0
4727 #: build/C/man3/pthread_kill_other_threads_np.3:45
4729 "B<pthread_kill_other_threads_np>() only has an effect in the LinuxThreads "
4730 "threading implementation. On that implementation, calling this function "
4731 "causes the immediate termination of all threads in the application, except "
4732 "the calling thread. The cancellation state and cancellation type of the "
4733 "to-be-terminated threads are ignored, and the cleanup handlers are not "
4734 "called in those threads."
4738 #: build/C/man3/pthread_kill_other_threads_np.3:57
4740 "B<pthread_kill_other_threads_np>() is intended to be called just before a "
4741 "thread calls B<execve>(2) or a similar function. This function is designed "
4742 "to address a limitation in the obsolete LinuxThreads implementation whereby "
4743 "the other threads of an application are not automatically terminated (as "
4744 "POSIX.1-2001 requires) during B<execve>(2)."
4748 #: build/C/man3/pthread_kill_other_threads_np.3:64
4750 "In the NPTL threading implementation, B<pthread_kill_other_threads_np>() "
4751 "exists, but does nothing. (Nothing needs to be done, because the "
4752 "implementation does the right thing during an B<execve>(2).)"
4756 #: build/C/man3/pthread_kill_other_threads_np.3:69
4758 "B<execve>(2), B<pthread_cancel>(3), B<pthread_setcancelstate>(3), "
4759 "B<pthread_setcanceltype>(3), B<pthreads>(7)"
4763 #: build/C/man3/pthread_self.3:24
4765 msgid "PTHREAD_SELF"
4769 #: build/C/man3/pthread_self.3:27
4770 msgid "pthread_self - obtain ID of the calling thread"
4774 #: build/C/man3/pthread_self.3:32
4776 msgid "B<pthread_t pthread_self(void);>\n"
4780 #: build/C/man3/pthread_self.3:44
4782 "The B<pthread_self>() function returns the ID of the calling thread. This "
4783 "is the same value that is returned in I<*thread> in the B<pthread_create>(3) "
4784 "call that created this thread."
4788 #: build/C/man3/pthread_self.3:46
4789 msgid "This function always succeeds, returning the calling thread's ID."
4793 #: build/C/man3/pthread_self.3:61
4795 "POSIX.1 allows an implementation wide freedom in choosing the type used to "
4796 "represent a thread ID; for example, representation using either an "
4797 "arithmetic type or a structure is permitted. Therefore, variables of type "
4798 "I<pthread_t> can't portably be compared using the C equality operator "
4799 "(B<==>); use B<pthread_equal>(3) instead."
4803 #: build/C/man3/pthread_self.3:65
4805 "Thread identifiers should be considered opaque: any attempt to use a thread "
4806 "ID other than in pthreads calls is nonportable and can lead to unspecified "
4811 #: build/C/man3/pthread_self.3:69
4813 "Thread IDs are only guaranteed to be unique within a process. A thread ID "
4814 "may be reused after a terminated thread has been joined, or a detached "
4815 "thread has terminated."
4819 #: build/C/man3/pthread_self.3:74
4821 "The thread ID returned by B<pthread_self>() is not the same thing as the "
4822 "kernel thread ID returned by a call to B<gettid>(2)."
4826 #: build/C/man3/pthread_self.3:77
4827 msgid "B<pthread_create>(3), B<pthread_equal>(3), B<pthreads>(7)"
4831 #: build/C/man3/pthread_setaffinity_np.3:24
4833 msgid "PTHREAD_SETAFFINITY_NP"
4837 #: build/C/man3/pthread_setaffinity_np.3:28
4839 "pthread_setaffinity_np, pthread_getaffinity_np - set/get CPU affinity of a "
4844 #: build/C/man3/pthread_setaffinity_np.3:37
4847 "B<int pthread_setaffinity_np(pthread_t >I<thread>B<, size_t "
4848 ">I<cpusetsize>B<,>\n"
4849 "B< const cpu_set_t *>I<cpuset>B<);>\n"
4850 "B<int pthread_getaffinity_np(pthread_t >I<thread>B<, size_t "
4851 ">I<cpusetsize>B<,>\n"
4852 "B< cpu_set_t *>I<cpuset>B<);>\n"
4856 #: build/C/man3/pthread_setaffinity_np.3:52
4858 "The B<pthread_setaffinity_np>() function sets the CPU affinity mask of the "
4859 "thread I<thread> to the CPU set pointed to by I<cpuset>. If the call is "
4860 "successful, and the thread is not currently running on one of the CPUs in "
4861 "I<cpuset>, then it is migrated to one of those CPUs."
4865 #: build/C/man3/pthread_setaffinity_np.3:59
4867 "The B<pthread_getaffinity_np>() function returns the CPU affinity mask of "
4868 "the thread I<thread> in the buffer pointed to by I<cpuset>."
4872 #: build/C/man3/pthread_setaffinity_np.3:75
4874 "The argument I<cpusetsize> is the length (in bytes) of the buffer pointed to "
4875 "by I<cpuset>. Typically, this argument would be specified as "
4876 "I<sizeof(cpu_set_t)>. (It may be some other value, if using the macros "
4877 "described in B<CPU_SET>(3) for dynamically allocating a CPU set.)"
4881 #: build/C/man3/pthread_setaffinity_np.3:79
4887 #: build/C/man3/pthread_setaffinity_np.3:82
4888 msgid "A supplied memory address was invalid."
4892 #: build/C/man3/pthread_setaffinity_np.3:91
4894 "(B<pthread_setaffinity_np>()) The affinity bit mask I<mask> contains no "
4895 "processors that are currently physically on the system and permitted to the "
4896 "thread according to any restrictions that may be imposed by the \"cpuset\" "
4897 "mechanism described in B<cpuset>(7)."
4901 #. Loic Domaigne commented: it seems that in the future the
4902 #. kernel developers want to make cpumask_t dynamic, so
4903 #. CONFIG_NR_CPUS might become obsolete in the future.
4905 #. The raw sched_getaffinity() system call returns the size (in bytes)
4906 #. of the cpumask_t type.
4908 #: build/C/man3/pthread_setaffinity_np.3:107
4910 "(B<pthread_setaffinity_np>()) I<cpuset> specified a CPU that was outside "
4911 "the set supported by the kernel. (The kernel configuration option "
4912 "B<CONFIG_NR_CPUS> defines the range of the set supported by the kernel data "
4913 "type used to represent CPU sets.)"
4917 #: build/C/man3/pthread_setaffinity_np.3:112
4919 "(B<pthread_getaffinity_np>()) I<cpusetsize> is smaller than the size of the "
4920 "affinity mask used by the kernel."
4924 #: build/C/man3/pthread_setaffinity_np.3:135
4926 "After a call to B<pthread_setaffinity_np>(), the set of CPUs on which the "
4927 "thread will actually run is the intersection of the set specified in the "
4928 "I<cpuset> argument and the set of CPUs actually present on the system. The "
4929 "system may further restrict the set of CPUs on which the thread runs if the "
4930 "\"cpuset\" mechanism described in B<cpuset>(7) is being used. These "
4931 "restrictions on the actual set of CPUs on which the thread will run are "
4932 "silently imposed by the kernel."
4936 #: build/C/man3/pthread_setaffinity_np.3:141
4938 "These functions are implemented on top of the B<sched_setaffinity>(2) and "
4939 "B<sched_getaffinity>(2) system calls."
4943 #: build/C/man3/pthread_setaffinity_np.3:152
4945 "A new thread created by B<pthread_create>(3) inherits a copy of its "
4946 "creator's CPU affinity mask."
4950 #: build/C/man3/pthread_setaffinity_np.3:160
4952 "In the following program, the main thread uses B<pthread_setaffinity_np>() "
4953 "to set its CPU affinity mask to include CPUs 0 to 7 (which may not all be "
4954 "available on the system), and then calls B<pthread_getaffinity_np>() to "
4955 "check the resulting CPU affinity mask of the thread."
4959 #: build/C/man3/pthread_setaffinity_np.3:167
4962 "#define _GNU_SOURCE\n"
4963 "#include E<lt>pthread.hE<gt>\n"
4964 "#include E<lt>stdio.hE<gt>\n"
4965 "#include E<lt>stdlib.hE<gt>\n"
4966 "#include E<lt>errno.hE<gt>\n"
4970 #: build/C/man3/pthread_setaffinity_np.3:177
4974 "main(int argc, char *argv[])\n"
4977 " cpu_set_t cpuset;\n"
4978 " pthread_t thread;\n"
4982 #: build/C/man3/pthread_setaffinity_np.3:179
4984 msgid " thread = pthread_self();\n"
4988 #: build/C/man3/pthread_setaffinity_np.3:181
4990 msgid " /* Set affinity mask to include CPUs 0 to 7 */\n"
4994 #: build/C/man3/pthread_setaffinity_np.3:185
4997 " CPU_ZERO(&cpuset);\n"
4998 " for (j = 0; j E<lt> 8; j++)\n"
4999 " CPU_SET(j, &cpuset);\n"
5003 #: build/C/man3/pthread_setaffinity_np.3:189
5006 " s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);\n"
5008 " handle_error_en(s, \"pthread_setaffinity_np\");\n"
5012 #: build/C/man3/pthread_setaffinity_np.3:191
5014 msgid " /* Check the actual affinity mask assigned to the thread */\n"
5018 #: build/C/man3/pthread_setaffinity_np.3:195
5021 " s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);\n"
5023 " handle_error_en(s, \"pthread_getaffinity_np\");\n"
5027 #: build/C/man3/pthread_setaffinity_np.3:200
5030 " printf(\"Set returned by pthread_getaffinity_np() contained:\\en\");\n"
5031 " for (j = 0; j E<lt> CPU_SETSIZE; j++)\n"
5032 " if (CPU_ISSET(j, &cpuset))\n"
5033 " printf(\" CPU %d\\en\", j);\n"
5037 #: build/C/man3/pthread_setaffinity_np.3:203 build/C/man3/pthread_setschedparam.3:428
5040 " exit(EXIT_SUCCESS);\n"
5045 #: build/C/man3/pthread_setaffinity_np.3:211
5047 "B<sched_setaffinity>(2), B<sched_setscheduler>(2), "
5048 "B<pthread_attr_setaffinity_np>(3), B<pthread_self>(3), B<sched_getcpu>(3), "
5049 "B<cpuset>(7), B<pthreads>(7)"
5053 #: build/C/man3/pthread_setcancelstate.3:24
5055 msgid "PTHREAD_SETCANCELSTATE"
5059 #: build/C/man3/pthread_setcancelstate.3:28
5061 "pthread_setcancelstate, pthread_setcanceltype - set cancelability state and "
5066 #: build/C/man3/pthread_setcancelstate.3:34
5069 "B<int pthread_setcancelstate(int >I<state>B<, int *>I<oldstate>B<);>\n"
5070 "B<int pthread_setcanceltype(int >I<type>B<, int *>I<oldtype>B<);>\n"
5074 #: build/C/man3/pthread_setcancelstate.3:49
5076 "The B<pthread_setcancelstate>() sets the cancelability state of the calling "
5077 "thread to the value given in I<state>. The previous cancelability state of "
5078 "the thread is returned in the buffer pointed to by I<oldstate>. The "
5079 "I<state> argument must have one of the following values:"
5083 #: build/C/man3/pthread_setcancelstate.3:49
5085 msgid "B<PTHREAD_CANCEL_ENABLE>"
5089 #: build/C/man3/pthread_setcancelstate.3:56
5091 "The thread is cancelable. This is the default cancelability state in all "
5092 "new threads, including the initial thread. The thread's cancelability type "
5093 "determines when a cancelable thread will respond to a cancellation request."
5097 #: build/C/man3/pthread_setcancelstate.3:56
5099 msgid "B<PTHREAD_CANCEL_DISABLE>"
5103 #: build/C/man3/pthread_setcancelstate.3:61
5105 "The thread is not cancelable. If a cancellation request is received, it is "
5106 "blocked until cancelability is enabled."
5110 #: build/C/man3/pthread_setcancelstate.3:73
5112 "The B<pthread_setcanceltype>() sets the cancelability type of the calling "
5113 "thread to the value given in I<type>. The previous cancelability type of "
5114 "the thread is returned in the buffer pointed to by I<oldtype>. The I<type> "
5115 "argument must have one of the following values:"
5119 #: build/C/man3/pthread_setcancelstate.3:73
5121 msgid "B<PTHREAD_CANCEL_DEFERRED>"
5125 #: build/C/man3/pthread_setcancelstate.3:80
5127 "A cancellation request is deferred until the thread next calls a function "
5128 "that is a cancellation point (see B<pthreads>(7)). This is the default "
5129 "cancelability type in all new threads, including the initial thread."
5133 #: build/C/man3/pthread_setcancelstate.3:80
5135 msgid "B<PTHREAD_CANCEL_ASYNCHRONOUS>"
5139 #: build/C/man3/pthread_setcancelstate.3:86
5141 "The thread can be canceled at any time. (Typically, it will be canceled "
5142 "immediately upon receiving a cancellation request, but the system doesn't "
5147 #: build/C/man3/pthread_setcancelstate.3:90
5149 "The set-and-get operation performed by each of these functions is atomic "
5150 "with respect to other threads in the process calling the same function."
5154 #: build/C/man3/pthread_setcancelstate.3:97
5155 msgid "The B<pthread_setcancelstate>() can fail with the following error:"
5159 #: build/C/man3/pthread_setcancelstate.3:101
5160 msgid "Invalid value for I<state>."
5164 #: build/C/man3/pthread_setcancelstate.3:105
5165 msgid "The B<pthread_setcanceltype>() can fail with the following error:"
5169 #. Available since glibc 2.0
5171 #: build/C/man3/pthread_setcancelstate.3:111
5172 msgid "Invalid value for I<type>."
5176 #: build/C/man3/pthread_setcancelstate.3:116
5178 "For details of what happens when a thread is canceled, see "
5179 "B<pthread_cancel>(3)."
5183 #: build/C/man3/pthread_setcancelstate.3:123
5185 "Briefly disabling cancelability is useful if a thread performs some critical "
5186 "action that must not be interrupted by a cancellation request. Beware of "
5187 "disabling cancelability for long periods, or around operations that may "
5188 "block for long periods, since that will render the thread unresponsive to "
5189 "cancellation requests."
5193 #: build/C/man3/pthread_setcancelstate.3:154
5195 "Setting the cancelability type to B<PTHREAD_CANCEL_ASYNCHRONOUS> is rarely "
5196 "useful. Since the thread could be canceled at I<any> time, it cannot safely "
5197 "reserve resources (e.g., allocating memory with B<malloc>(3)), acquire "
5198 "mutexes, semaphores, or locks, and so on. Reserving resources is unsafe "
5199 "because the application has no way of knowing what the state of these "
5200 "resources is when the thread is canceled; that is, did cancellation occur "
5201 "before the resources were reserved, while they were reserved, or after they "
5202 "were released? Furthermore, some internal data structures (e.g., the linked "
5203 "list of free blocks managed by the B<malloc>(3) family of functions) may be "
5204 "left in an inconsistent state if cancellation occurs in the middle of the "
5205 "function call. Consequently, clean-up handlers cease to be useful. "
5206 "Functions that can be safely asynchronously canceled are called "
5207 "I<async-cancel-safe functions>. POSIX.1-2001 only requires that "
5208 "B<pthread_cancel>(3), B<pthread_setcancelstate>(), and "
5209 "B<pthread_setcanceltype>() be async-cancel-safe. In general, other library "
5210 "functions can't be safely called from an asynchronously cancelable thread. "
5211 "One of the few circumstances in which asynchronous cancelability is useful "
5212 "is for cancellation of a thread that is in a pure compute-bound loop."
5215 #. It looks like at least Solaris, FreeBSD and Tru64 support this.
5217 #: build/C/man3/pthread_setcancelstate.3:172
5219 "The Linux threading implementations permit the I<oldstate> argument of "
5220 "B<pthread_setcancelstate>() to be NULL, in which case the information about "
5221 "the previous cancelability state is not returned to the caller. Many other "
5222 "implementations also permit a NULL I<oldstat> argument, but POSIX.1-2001 "
5223 "does not specify this point, so portable applications should always specify "
5224 "a non-NULL value in I<oldstate>. A precisely analogous set of statements "
5225 "applies for the I<oldtype> argument of B<pthread_setcanceltype>()."
5229 #: build/C/man3/pthread_setcancelstate.3:175
5230 msgid "See B<pthread_cancel>(3)."
5234 #: build/C/man3/pthread_setcancelstate.3:179
5236 "B<pthread_cancel>(3), B<pthread_cleanup_push>(3), B<pthread_testcancel>(3), "
5241 #: build/C/man3/pthread_setconcurrency.3:23
5243 msgid "PTHREAD_SETCONCURRENCY"
5247 #: build/C/man3/pthread_setconcurrency.3:23 build/C/man3/pthread_yield.3:23
5253 #: build/C/man3/pthread_setconcurrency.3:27
5255 "pthread_setconcurrency, pthread_getconcurrency - set/get the concurrency "
5260 #: build/C/man3/pthread_setconcurrency.3:33
5263 "B<int pthread_setconcurrency(int >I<new_level>B<);>\n"
5264 "B<int pthread_getconcurrency(void);>\n"
5268 #: build/C/man3/pthread_setconcurrency.3:46
5270 "The B<pthread_setconcurrency>() function informs the implementation of the "
5271 "application's desired concurrency level, specified in I<new_level>. The "
5272 "implementation only takes this as a hint: POSIX.1 does not specify the level "
5273 "of concurrency that should be provided as a result of calling "
5274 "B<pthread_setconcurrency>()."
5278 #: build/C/man3/pthread_setconcurrency.3:51
5280 "Specifying I<new_level> as 0 instructs the implementation to manage the "
5281 "concurrency level as it deems appropriate."
5285 #: build/C/man3/pthread_setconcurrency.3:54
5287 "B<pthread_getconcurrency>() returns the current value of the concurrency "
5288 "level for this process."
5292 #: build/C/man3/pthread_setconcurrency.3:59
5294 "On success, B<pthread_setconcurrency>() returns 0; on error, it returns a "
5295 "nonzero error number."
5299 #: build/C/man3/pthread_setconcurrency.3:66
5301 "B<pthread_getconcurrency>() always succeeds, returning the concurrency "
5302 "level set by a previous call to B<pthread_setconcurrency>(), or 0, if "
5303 "B<pthread_setconcurrency>() has not previously been called."
5307 #: build/C/man3/pthread_setconcurrency.3:69
5308 msgid "B<pthread_setconcurrency>() can fail with the following error:"
5312 #: build/C/man3/pthread_setconcurrency.3:73
5313 msgid "I<new_level> is negative."
5317 #: build/C/man3/pthread_setconcurrency.3:79
5319 "POSIX.1-2001 also documents an B<EAGAIN> error (\"the value specified by "
5320 "I<new_level> would cause a system resource to be exceeded\")."
5324 #: build/C/man3/pthread_setconcurrency.3:81
5325 msgid "These functions are available in glibc since version 2.1."
5329 #: build/C/man3/pthread_setconcurrency.3:85
5330 msgid "The default concurrency level is 0."
5334 #: build/C/man3/pthread_setconcurrency.3:92
5336 "Concurrency levels are only meaningful for M:N threading implementations, "
5337 "where at any moment a subset of a process's set of user-level threads may be "
5338 "bound to a smaller number of kernel-scheduling entities. Setting the "
5339 "concurrency level allows the application to give the system a hint as to the "
5340 "number of kernel-scheduling entities that should be provided for efficient "
5341 "execution of the application."
5345 #: build/C/man3/pthread_setconcurrency.3:98
5347 "Both LinuxThreads and NPTL are 1:1 threading implementations, so setting the "
5348 "concurrency level has no meaning. In other words, on Linux these functions "
5349 "merely exist for compatibility with other systems, and they have no effect "
5350 "on the execution of a program."
5354 #: build/C/man3/pthread_setconcurrency.3:100
5355 msgid "B<pthread_attr_setscope>(3), B<pthreads>(7)"
5359 #: build/C/man3/pthread_setschedparam.3:24
5361 msgid "PTHREAD_SETSCHEDPARAM"
5365 #: build/C/man3/pthread_setschedparam.3:28
5367 "pthread_setschedparam, pthread_getschedparam - set/get scheduling policy and "
5368 "parameters of a thread"
5372 #: build/C/man3/pthread_setschedparam.3:36
5375 "B<pthread_setschedparam(pthread_t >I<thread>B<, int >I<policy>B<,>\n"
5376 "B< const struct sched_param *>I<param>B<);>\n"
5377 "B<pthread_getschedparam(pthread_t >I<thread>B<, int *>I<policy>B<,>\n"
5378 "B< struct sched_param *>I<param>B<);>\n"
5382 #: build/C/man3/pthread_setschedparam.3:44
5384 "The B<pthread_setschedparam>() function sets the scheduling policy and "
5385 "parameters of the thread I<thread>."
5388 #. FIXME . pthread_setschedparam() places no restriction on the policy,
5389 #. but pthread_attr_setschedpolicy() restricts policy to RR/FIFO/OTHER
5390 #. http://sourceware.org/bugzilla/show_bug.cgi?id=7013
5392 #: build/C/man3/pthread_setschedparam.3:55
5394 "I<policy> specifies the new scheduling policy for I<thread>. The supported "
5395 "values for I<policy>, and their semantics, are described in "
5396 "B<sched_setscheduler>(2)."
5400 #: build/C/man3/pthread_setschedparam.3:61
5402 "The structure pointed to by I<param> specifies the new scheduling parameters "
5403 "for I<thread>. Scheduling parameters are maintained in the following "
5407 #. FIXME . nptl/pthread_setschedparam.c has the following
5408 #. /* If the thread should have higher priority because of some
5409 #. PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */
5410 #. Eventually (perhaps after writing the mutexattr pages), we
5411 #. may want to add something on the topic to this page.
5413 #: build/C/man3/pthread_setschedparam.3:102
5415 "The B<pthread_getschedparam>() function returns the scheduling policy and "
5416 "parameters of the thread I<thread>, in the buffers pointed to by I<policy> "
5417 "and I<param>, respectively. The returned priority value is that set by the "
5418 "most recent B<pthread_setschedparam>(), B<pthread_setschedprio>(3), or "
5419 "B<pthread_create>(3) call that affected I<thread>. The returned priority "
5420 "does not reflect any temporary priority adjustments as a result of calls to "
5421 "any priority inheritance or priority ceiling functions (see, for example, "
5422 "B<pthread_mutexattr_setprioceiling>(3) and "
5423 "B<pthread_mutexattr_setprotocol>(3))."
5427 #: build/C/man3/pthread_setschedparam.3:110
5429 "On success, these functions return 0; on error, they return a nonzero error "
5430 "number. If B<pthread_setschedparam>() fails, the scheduling policy and "
5431 "parameters of I<thread> are not changed."
5435 #: build/C/man3/pthread_setschedparam.3:112
5436 msgid "Both of these functions can fail with the following error:"
5440 #: build/C/man3/pthread_setschedparam.3:120
5441 msgid "B<pthread_setschedparam>() may additionally fail with the following errors:"
5445 #: build/C/man3/pthread_setschedparam.3:127
5447 "I<policy> is not a recognized policy, or I<param> does not make sense for "
5452 #: build/C/man3/pthread_setschedparam.3:131
5454 "The caller does not have appropriate privileges to set the specified "
5455 "scheduling policy and parameters."
5459 #. Available since glibc 2.0
5461 #: build/C/man3/pthread_setschedparam.3:139
5463 "POSIX.1-2001 also documents an B<ENOTSUP> (\"attempt was made to set the "
5464 "policy or scheduling parameters to an unsupported value\") error for "
5465 "B<pthread_setschedparam>()."
5469 #: build/C/man3/pthread_setschedparam.3:147
5471 "For a description of the permissions required to, and the effect of, "
5472 "changing a thread's scheduling policy and priority, and details of the "
5473 "permitted ranges for priorities in each scheduling policy, see "
5474 "B<sched_setscheduler>(2)."
5478 #: build/C/man3/pthread_setschedparam.3:154
5480 "The program below demonstrates the use of B<pthread_setschedparam>() and "
5481 "B<pthread_getschedparam>(), as well as the use of a number of other "
5482 "scheduling-related pthreads functions."
5486 #: build/C/man3/pthread_setschedparam.3:170
5488 "In the following run, the main thread sets its scheduling policy to "
5489 "B<SCHED_FIFO> with a priority of 10, and initializes a thread attributes "
5490 "object with a scheduling policy attribute of B<SCHED_RR> and a scheduling "
5491 "priority attribute of 20. The program then sets (using "
5492 "B<pthread_attr_setinheritsched>(3)) the inherit scheduler attribute of the "
5493 "thread attributes object to B<PTHREAD_EXPLICIT_SCHED>, meaning that threads "
5494 "created using this attributes object should take their scheduling attributes "
5495 "from the thread attributes object. The program then creates a thread using "
5496 "the thread attributes object, and that thread displays its scheduling policy "
5501 #: build/C/man3/pthread_setschedparam.3:178
5504 "$ B<su> # Need privilege to set real-time scheduling policies\n"
5506 "# B<./a.out -mf10 -ar20 -i e>\n"
5507 "Scheduler settings of main thread\n"
5508 " policy=SCHED_FIFO, priority=10\n"
5512 #: build/C/man3/pthread_setschedparam.3:182
5515 "Scheduler settings in \\(aqattr\\(aq\n"
5516 " policy=SCHED_RR, priority=20\n"
5517 " inheritsched is EXPLICIT\n"
5521 #: build/C/man3/pthread_setschedparam.3:185
5524 "Scheduler attributes of new thread\n"
5525 " policy=SCHED_RR, priority=20\n"
5529 #: build/C/man3/pthread_setschedparam.3:190
5531 "In the above output, one can see that the scheduling policy and priority "
5532 "were taken from the values specified in the thread attributes object."
5536 #: build/C/man3/pthread_setschedparam.3:197
5538 "The next run is the same as the previous, except that the inherit scheduler "
5539 "attribute is set to B<PTHREAD_INHERIT_SCHED>, meaning that threads created "
5540 "using the thread attributes object should ignore the scheduling attributes "
5541 "specified in the attributes object and instead take their scheduling "
5542 "attributes from the creating thread."
5546 #: build/C/man3/pthread_setschedparam.3:203
5549 "# B<./a.out -mf10 -ar20 -i i>\n"
5550 "Scheduler settings of main thread\n"
5551 " policy=SCHED_FIFO, priority=10\n"
5555 #: build/C/man3/pthread_setschedparam.3:207
5558 "Scheduler settings in \\(aqattr\\(aq\n"
5559 " policy=SCHED_RR, priority=20\n"
5560 " inheritsched is INHERIT\n"
5564 #: build/C/man3/pthread_setschedparam.3:210
5567 "Scheduler attributes of new thread\n"
5568 " policy=SCHED_FIFO, priority=10\n"
5572 #: build/C/man3/pthread_setschedparam.3:216
5574 "In the above output, one can see that the scheduling policy and priority "
5575 "were taken from the creating thread, rather than the thread attributes "
5580 #: build/C/man3/pthread_setschedparam.3:222
5582 "Note that if we had omitted the I<-i\\ i> option, the output would have been "
5583 "the same, since B<PTHREAD_INHERIT_SCHED> is the default for the inherit "
5584 "scheduler attribute."
5588 #: build/C/man3/pthread_setschedparam.3:226
5590 msgid "/* pthreads_sched_test.c */\n"
5594 #: build/C/man3/pthread_setschedparam.3:232
5597 "#include E<lt>pthread.hE<gt>\n"
5598 "#include E<lt>stdio.hE<gt>\n"
5599 "#include E<lt>stdlib.hE<gt>\n"
5600 "#include E<lt>unistd.hE<gt>\n"
5601 "#include E<lt>errno.hE<gt>\n"
5605 #: build/C/man3/pthread_setschedparam.3:241
5609 "usage(char *prog_name, char *msg)\n"
5611 " if (msg != NULL)\n"
5612 " fputs(msg, stderr);\n"
5616 #: build/C/man3/pthread_setschedparam.3:258
5619 " fprintf(stderr, \"Usage: %s [options]\\en\", prog_name);\n"
5620 " fprintf(stderr, \"Options are:\\en\");\n"
5621 "#define fpe(msg) fprintf(stderr, \"\\et%s\", msg); /* Shorter */\n"
5622 " fpe(\"-aE<lt>policyE<gt>E<lt>prioE<gt> Set scheduling policy and "
5623 "priority in\\en\");\n"
5624 " fpe(\" thread attributes object\\en\");\n"
5625 " fpe(\" E<lt>policyE<gt> can be\\en\");\n"
5626 " fpe(\" f SCHED_FIFO\\en\");\n"
5627 " fpe(\" r SCHED_RR\\en\");\n"
5628 " fpe(\" o SCHED_OTHER\\en\");\n"
5629 " fpe(\"-A Use default thread attributes object\\en\");\n"
5630 " fpe(\"-i {e|s} Set inherit scheduler attribute to\\en\");\n"
5631 " fpe(\" \\(aqexplicit\\(aq or \\(aqinherit\\(aq\\en\");\n"
5632 " fpe(\"-mE<lt>policyE<gt>E<lt>prioE<gt> Set scheduling policy and "
5633 "priority on\\en\");\n"
5634 " fpe(\" main thread before pthread_create() "
5636 " exit(EXIT_FAILURE);\n"
5641 #: build/C/man3/pthread_setschedparam.3:269
5645 "get_policy(char p, int *policy)\n"
5648 " case \\(aqf\\(aq: *policy = SCHED_FIFO; return 1;\n"
5649 " case \\(aqr\\(aq: *policy = SCHED_RR; return 1;\n"
5650 " case \\(aqo\\(aq: *policy = SCHED_OTHER; return 1;\n"
5651 " default: return 0;\n"
5657 #: build/C/man3/pthread_setschedparam.3:280
5661 "display_sched_attr(int policy, struct sched_param *param)\n"
5663 " printf(\" policy=%s, priority=%d\\en\",\n"
5664 " (policy == SCHED_FIFO) ? \"SCHED_FIFO\" :\n"
5665 " (policy == SCHED_RR) ? \"SCHED_RR\" :\n"
5666 " (policy == SCHED_OTHER) ? \"SCHED_OTHER\" :\n"
5668 " param-E<gt>sched_priority);\n"
5673 #: build/C/man3/pthread_setschedparam.3:286
5677 "display_thread_sched_attr(char *msg)\n"
5680 " struct sched_param param;\n"
5684 #: build/C/man3/pthread_setschedparam.3:290
5687 " s = pthread_getschedparam(pthread_self(), &policy, ¶m);\n"
5689 " handle_error_en(s, \"pthread_getschedparam\");\n"
5693 #: build/C/man3/pthread_setschedparam.3:294
5696 " printf(\"%s\\en\", msg);\n"
5697 " display_sched_attr(policy, ¶m);\n"
5702 #: build/C/man3/pthread_setschedparam.3:299
5706 "thread_start(void *arg)\n"
5708 " display_thread_sched_attr(\"Scheduler attributes of new thread\");\n"
5712 #: build/C/man3/pthread_setschedparam.3:302
5720 #: build/C/man3/pthread_setschedparam.3:312
5724 "main(int argc, char *argv[])\n"
5726 " int s, opt, inheritsched, use_null_attrib, policy;\n"
5727 " pthread_t thread;\n"
5728 " pthread_attr_t attr;\n"
5729 " pthread_attr_t *attrp;\n"
5730 " char *attr_sched_str, *main_sched_str, *inheritsched_str;\n"
5731 " struct sched_param param;\n"
5735 #: build/C/man3/pthread_setschedparam.3:314
5737 msgid " /* Process command-line options */\n"
5741 #: build/C/man3/pthread_setschedparam.3:319
5744 " use_null_attrib = 0;\n"
5745 " attr_sched_str = NULL;\n"
5746 " main_sched_str = NULL;\n"
5747 " inheritsched_str = NULL;\n"
5751 #: build/C/man3/pthread_setschedparam.3:329
5754 " while ((opt = getopt(argc, argv, \"a:Ai:m:\")) != -1) {\n"
5756 " case \\(aqa\\(aq: attr_sched_str = optarg; break;\n"
5757 " case \\(aqA\\(aq: use_null_attrib = 1; break;\n"
5758 " case \\(aqi\\(aq: inheritsched_str = optarg; break;\n"
5759 " case \\(aqm\\(aq: main_sched_str = optarg; break;\n"
5760 " default: usage(argv[0], \"Unrecognized option\\en\");\n"
5766 #: build/C/man3/pthread_setschedparam.3:333
5769 " if (use_null_attrib &&\n"
5770 " (inheritsched_str != NULL || attr_sched_str != NULL))\n"
5771 " usage(argv[0], \"Can\\(aqt specify -A with -i or -a\\en\");\n"
5775 #: build/C/man3/pthread_setschedparam.3:336
5778 " /* Optionally set scheduling attributes of main thread,\n"
5779 " and display the attributes */\n"
5783 #: build/C/man3/pthread_setschedparam.3:341
5786 " if (main_sched_str != NULL) {\n"
5787 " if (!get_policy(main_sched_str[0], &policy))\n"
5788 " usage(argv[0], \"Bad policy for main thread (-s)\\en\");\n"
5789 " param.sched_priority = strtol(&main_sched_str[1], NULL, 0);\n"
5793 #: build/C/man3/pthread_setschedparam.3:346
5796 " s = pthread_setschedparam(pthread_self(), policy, ¶m);\n"
5798 " handle_error_en(s, \"pthread_setschedparam\");\n"
5803 #: build/C/man3/pthread_setschedparam.3:349
5806 " display_thread_sched_attr(\"Scheduler settings of main thread\");\n"
5807 " printf(\"\\en\");\n"
5811 #: build/C/man3/pthread_setschedparam.3:351
5813 msgid " /* Initialize thread attributes object according to options */\n"
5817 #: build/C/man3/pthread_setschedparam.3:360
5820 " if (!use_null_attrib) {\n"
5821 " s = pthread_attr_init(&attr);\n"
5823 " handle_error_en(s, \"pthread_attr_init\");\n"
5829 #: build/C/man3/pthread_setschedparam.3:368
5832 " if (inheritsched_str != NULL) {\n"
5833 " if (inheritsched_str[0] == \\(aqe\\(aq)\n"
5834 " inheritsched = PTHREAD_EXPLICIT_SCHED;\n"
5835 " else if (inheritsched_str[0] == \\(aqi\\(aq)\n"
5836 " inheritsched = PTHREAD_INHERIT_SCHED;\n"
5838 " usage(argv[0], \"Value for -i must be \\(aqe\\(aq or "
5839 "\\(aqi\\(aq\\en\");\n"
5843 #: build/C/man3/pthread_setschedparam.3:373
5846 " s = pthread_attr_setinheritsched(&attr, inheritsched);\n"
5848 " handle_error_en(s, \"pthread_attr_setinheritsched\");\n"
5853 #: build/C/man3/pthread_setschedparam.3:379
5856 " if (attr_sched_str != NULL) {\n"
5857 " if (!get_policy(attr_sched_str[0], &policy))\n"
5859 " \"Bad policy for \\(aqattr\\(aq (-a)\\en\");\n"
5860 " param.sched_priority = strtol(&attr_sched_str[1], NULL, 0);\n"
5864 #: build/C/man3/pthread_setschedparam.3:387
5867 " s = pthread_attr_setschedpolicy(&attr, policy);\n"
5869 " handle_error_en(s, \"pthread_attr_setschedpolicy\");\n"
5870 " s = pthread_attr_setschedparam(&attr, ¶m);\n"
5872 " handle_error_en(s, \"pthread_attr_setschedparam\");\n"
5877 #: build/C/man3/pthread_setschedparam.3:390
5880 " /* If we initialized a thread attributes object, display\n"
5881 " the scheduling attributes that were set in the object */\n"
5885 #: build/C/man3/pthread_setschedparam.3:398
5888 " if (attrp != NULL) {\n"
5889 " s = pthread_attr_getschedparam(&attr, ¶m);\n"
5891 " handle_error_en(s, \"pthread_attr_getschedparam\");\n"
5892 " s = pthread_attr_getschedpolicy(&attr, &policy);\n"
5894 " handle_error_en(s, \"pthread_attr_getschedpolicy\");\n"
5898 #: build/C/man3/pthread_setschedparam.3:401
5901 " printf(\"Scheduler settings in \\(aqattr\\(aq\\en\");\n"
5902 " display_sched_attr(policy, ¶m);\n"
5906 #: build/C/man3/pthread_setschedparam.3:409
5909 " s = pthread_attr_getinheritsched(&attr, &inheritsched);\n"
5910 " printf(\" inheritsched is %s\\en\",\n"
5911 " (inheritsched == PTHREAD_INHERIT_SCHED) ? \"INHERIT\" :\n"
5912 " (inheritsched == PTHREAD_EXPLICIT_SCHED) ? \"EXPLICIT\" :\n"
5914 " printf(\"\\en\");\n"
5919 #: build/C/man3/pthread_setschedparam.3:411
5921 msgid " /* Create a thread that will display its scheduling attributes */\n"
5925 #: build/C/man3/pthread_setschedparam.3:415
5928 " s = pthread_create(&thread, attrp, &thread_start, NULL);\n"
5930 " handle_error_en(s, \"pthread_create\");\n"
5934 #: build/C/man3/pthread_setschedparam.3:417
5936 msgid " /* Destroy unneeded thread attributes object */\n"
5940 #: build/C/man3/pthread_setschedparam.3:425
5943 " s = pthread_join(thread, NULL);\n"
5945 " handle_error_en(s, \"pthread_join\");\n"
5949 #: build/C/man3/pthread_setschedparam.3:440
5951 "B<getrlimit>(2), B<sched_get_priority_min>(2), B<sched_setscheduler>(2), "
5952 "B<pthread_attr_init>(3), B<pthread_attr_setinheritsched>(3), "
5953 "B<pthread_attr_setschedparam>(3), B<pthread_attr_setschedpolicy>(3), "
5954 "B<pthread_create>(3), B<pthread_self>(3), B<pthread_setschedprio>(3), "
5959 #: build/C/man3/pthread_setschedprio.3:24
5961 msgid "PTHREAD_SETSCHEDPRIO"
5965 #: build/C/man3/pthread_setschedprio.3:24
5971 #: build/C/man3/pthread_setschedprio.3:27
5972 msgid "pthread_setschedprio - set scheduling priority of a thread"
5976 #: build/C/man3/pthread_setschedprio.3:32
5978 msgid "B<pthread_setschedprio(pthread_t >I<thread>B<, int >I<prio>B<);>\n"
5981 #. FIXME . nptl/pthread_setschedprio.c has the following
5982 #. /* If the thread should have higher priority because of some
5983 #. PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */
5984 #. Eventually (perhaps after writing the mutexattr pages), we
5985 #. may want to add something on the topic to this page.
5986 #. nptl/pthread_setschedparam.c has a similar case.
5988 #: build/C/man3/pthread_setschedprio.3:51
5990 "The B<pthread_setschedprio>() function sets the scheduling priority of the "
5991 "thread I<thread> to the value specified in I<prio>. (By contrast "
5992 "B<pthread_setschedparam>(3) changes both the scheduling policy and priority "
5997 #: build/C/man3/pthread_setschedprio.3:59
5999 "On success, this function returns 0; on error, it returns a nonzero error "
6000 "number. If B<pthread_setschedprio>() fails, the scheduling priority of "
6001 "I<thread> is not changed."
6005 #: build/C/man3/pthread_setschedprio.3:64
6006 msgid "I<prio> is not valid for the scheduling policy of the specified thread."
6010 #: build/C/man3/pthread_setschedprio.3:68
6012 "The caller does not have appropriate privileges to set the specified "
6017 #: build/C/man3/pthread_setschedprio.3:79
6019 "POSIX.1-2001 also documents an B<ENOTSUP> (\"attempt was made to set the "
6020 "priority to an unsupported value\") error for B<pthread_setschedparam>(3)."
6024 #: build/C/man3/pthread_setschedprio.3:81
6025 msgid "This function is available in glibc since version 2.3.4."
6029 #: build/C/man3/pthread_setschedprio.3:89
6031 "For a description of the permissions required to, and the effect of, "
6032 "changing a thread's scheduling priority, and details of the permitted ranges "
6033 "for priorities in each scheduling policy, see B<sched_setscheduler>(2)."
6037 #: build/C/man3/pthread_setschedprio.3:100
6039 "B<getrlimit>(2), B<sched_get_priority_min>(2), B<sched_setscheduler>(2), "
6040 "B<pthread_attr_init>(3), B<pthread_attr_setinheritsched>(3), "
6041 "B<pthread_attr_setschedparam>(3), B<pthread_attr_setschedpolicy>(3), "
6042 "B<pthread_create>(3), B<pthread_self>(3), B<pthread_setschedparam>(3), "
6047 #: build/C/man3/pthread_sigmask.3:24
6049 msgid "PTHREAD_SIGMASK"
6053 #: build/C/man3/pthread_sigmask.3:24
6059 #: build/C/man3/pthread_sigmask.3:27
6060 msgid "pthread_sigmask - examine and change mask of blocked signals"
6064 #: build/C/man3/pthread_sigmask.3:33
6067 "B<int pthread_sigmask(int >I<how>B<, const sigset_t *>I<set>B<, sigset_t "
6068 "*>I<oldset>B<);>\n"
6072 #: build/C/man3/pthread_sigmask.3:44
6074 "The B<pthread_sigmask>() function is just like B<sigprocmask>(2), with the "
6075 "difference that its use in multithreaded programs is explicitly specified by "
6076 "POSIX.1-2001. Other differences are noted in this page."
6080 #: build/C/man3/pthread_sigmask.3:47
6082 "For a description of the arguments and operation of this function, see "
6083 "B<sigprocmask>(2)."
6087 #: build/C/man3/pthread_sigmask.3:52
6089 "On success, B<pthread_sigmask>() returns 0; on error, it returns an error "
6094 #: build/C/man3/pthread_sigmask.3:55
6095 msgid "See B<sigprocmask>(2)."
6099 #: build/C/man3/pthread_sigmask.3:59
6100 msgid "A new thread inherits a copy of its creator's signal mask."
6104 #: build/C/man3/pthread_sigmask.3:64
6106 "The program below blocks some signals in the main thread, and then creates a "
6107 "dedicated thread to fetch those signals via B<sigwait>(3). The following "
6108 "shell session demonstrates its use:"
6112 #: build/C/man3/pthread_sigmask.3:75
6117 "$B< kill -QUIT %1>\n"
6118 "Signal handling thread got signal 3\n"
6119 "$B< kill -USR1 %1>\n"
6120 "Signal handling thread got signal 10\n"
6121 "$B< kill -TERM %1>\n"
6122 "[1]+ Terminated ./a.out\n"
6126 #: build/C/man3/pthread_sigmask.3:86
6129 "#include E<lt>pthread.hE<gt>\n"
6130 "#include E<lt>stdio.hE<gt>\n"
6131 "#include E<lt>stdlib.hE<gt>\n"
6132 "#include E<lt>unistd.hE<gt>\n"
6133 "#include E<lt>signal.hE<gt>\n"
6134 "#include E<lt>errno.hE<gt>\n"
6138 #: build/C/man3/pthread_sigmask.3:88
6140 msgid "/* Simple error handling functions */\n"
6144 #: build/C/man3/pthread_sigmask.3:97
6148 "sig_thread(void *arg)\n"
6150 " sigset_t *set = (sigset_t *) arg;\n"
6155 #: build/C/man3/pthread_sigmask.3:105
6159 " s = sigwait(set, &sig);\n"
6161 " handle_error_en(s, \"sigwait\");\n"
6162 " printf(\"Signal handling thread got signal %d\\en\", sig);\n"
6168 #: build/C/man3/pthread_sigmask.3:112
6172 "main(int argc, char *argv[])\n"
6174 " pthread_t thread;\n"
6180 #: build/C/man3/pthread_sigmask.3:115
6183 " /* Block SIGQUIT and SIGUSR1; other threads created by main()\n"
6184 " will inherit a copy of the signal mask. */\n"
6188 #: build/C/man3/pthread_sigmask.3:122
6191 " sigemptyset(&set);\n"
6192 " sigaddset(&set, SIGQUIT);\n"
6193 " sigaddset(&set, SIGUSR1);\n"
6194 " s = pthread_sigmask(SIG_BLOCK, &set, NULL);\n"
6196 " handle_error_en(s, \"pthread_sigmask\");\n"
6200 #: build/C/man3/pthread_sigmask.3:126
6203 " s = pthread_create(&thread, NULL, &sig_thread, (void *) &set);\n"
6205 " handle_error_en(s, \"pthread_create\");\n"
6209 #: build/C/man3/pthread_sigmask.3:129
6212 " /* Main thread carries on to create other threads and/or do\n"
6217 #: build/C/man3/pthread_sigmask.3:132
6220 " pause(); /* Dummy pause so we can test program */\n"
6225 #: build/C/man3/pthread_sigmask.3:141
6227 "B<sigaction>(2), B<sigpending>(2), B<sigprocmask>(2) B<pthread_create>(3), "
6228 "B<pthread_kill>(3), B<sigsetops>(3), B<pthreads>(7), B<signal>(7)"
6232 #: build/C/man3/pthread_sigqueue.3:23
6234 msgid "PTHREAD_SIGQUEUE"
6238 #: build/C/man3/pthread_sigqueue.3:23
6244 #: build/C/man3/pthread_sigqueue.3:26
6245 msgid "pthread_sigqueue - queue a signal and data to a thread"
6249 #: build/C/man3/pthread_sigqueue.3:32
6252 "B<int pthread_sigqueue(pthread_t *>I<thread>B<, int >I<sig>B<,>\n"
6253 "B< const union sigval >I<value>B<);>\n"
6257 #: build/C/man3/pthread_sigqueue.3:43
6258 msgid "B<pthread_sigqueue>(): _GNU_SOURCE"
6262 #: build/C/man3/pthread_sigqueue.3:51
6264 "The B<pthread_sigqueue>() function performs a similar task to "
6265 "B<sigqueue>(3), but, rather than sending a signal to another process, it "
6266 "sends a signal to another thread in the same process as the calling thread."
6270 #: build/C/man3/pthread_sigqueue.3:63
6272 "The I<thread> argument is the ID of another thread in the same process as "
6273 "the caller. The I<sig> argument specifies the signal to be sent. The "
6274 "I<value> argument specifies data to accompany the signal; see B<sigqueue>(3) "
6279 #: build/C/man3/pthread_sigqueue.3:68
6281 "On success, B<pthread_sigqueue>() returns 0; on error, it returns an error "
6286 #: build/C/man3/pthread_sigqueue.3:75
6288 "The limit of signals which may be queued has been reached. (See "
6289 "B<signal>(7) for further information.)"
6293 #: build/C/man3/pthread_sigqueue.3:79
6294 msgid "I<sig> was invalid."
6298 #: build/C/man3/pthread_sigqueue.3:79
6304 #: build/C/man3/pthread_sigqueue.3:83
6305 msgid "B<pthread_sigqueue>() is not supported on this system."
6309 #: build/C/man3/pthread_sigqueue.3:87
6310 msgid "I<thread> is not valid."
6314 #: build/C/man3/pthread_sigqueue.3:91
6315 msgid "The B<pthread_sigqueue>() function first appeared in glibc 2.11."
6319 #: build/C/man3/pthread_sigqueue.3:93
6320 msgid "This function is a GNU extension."
6324 #: build/C/man3/pthread_sigqueue.3:100
6326 "B<rt_tgsigqueueinfo>(2), B<sigaction>(2), B<pthread_sigmask>(3), "
6327 "B<sigqueue>(3), B<sigwait>(3), B<pthreads>(7), B<signal>(7)"
6331 #: build/C/man3/pthread_testcancel.3:24
6333 msgid "PTHREAD_TESTCANCEL"
6337 #: build/C/man3/pthread_testcancel.3:24
6343 #: build/C/man3/pthread_testcancel.3:27
6344 msgid "pthread_testcancel - request delivery of any pending cancellation request"
6348 #: build/C/man3/pthread_testcancel.3:32
6350 msgid "B<void pthread_testcancel(void);>\n"
6354 #: build/C/man3/pthread_testcancel.3:41
6356 "Calling B<pthread_testcancel>() creates a cancellation point within the "
6357 "calling thread, so that a thread that is otherwise executing code that "
6358 "contains no cancellation points will respond to a cancellation request."
6362 #: build/C/man3/pthread_testcancel.3:48
6364 "If cancelability is disabled (using B<pthread_setcancelstate>(3)), or no "
6365 "cancellation request is pending, then a call to B<pthread_testcancel>(3) "
6370 #: build/C/man3/pthread_testcancel.3:52
6372 "This function does not return a value. If the calling thread is canceled as "
6373 "a consequence of a call to this function, then the function does not return."
6377 #: build/C/man3/pthread_testcancel.3:61
6378 msgid "See B<pthread_cleanup_push>(3)."
6382 #: build/C/man3/pthread_testcancel.3:65
6384 "B<pthread_cancel>(3), B<pthread_cleanup_push>(3), "
6385 "B<pthread_setcancelstate>(3), B<pthreads>(7)"
6389 #: build/C/man3/pthread_tryjoin_np.3:24
6391 msgid "PTHREAD_TRYJOIN_NP"
6395 #: build/C/man3/pthread_tryjoin_np.3:28
6397 "pthread_tryjoin_np, pthread_timedjoin_np - try to join with a terminated "
6402 #: build/C/man3/pthread_tryjoin_np.3:34
6404 msgid "B<int pthread_tryjoin_np(pthread_t >I<thread>B<, void **>I<retval>B<);>\n"
6408 #: build/C/man3/pthread_tryjoin_np.3:37
6411 "B<int pthread_timedjoin_np(pthread_t >I<thread>B<, void **>I<retval>B<,>\n"
6412 "B< const struct timespec *>I<abstime>B<);>\n"
6416 #: build/C/man3/pthread_tryjoin_np.3:44
6418 "These functions operate in the same way as B<pthread_join>(3), except for "
6419 "the differences described on this page."
6423 #: build/C/man3/pthread_tryjoin_np.3:56
6425 "The B<pthread_tryjoin_np>() function performs a nonblocking join with the "
6426 "thread I<thread>, returning the exit status of the thread in I<*retval>. If "
6427 "I<thread> has not yet terminated, then instead of blocking, as is done by "
6428 "B<pthread_join>(3), the call returns an error."
6432 #: build/C/man3/pthread_tryjoin_np.3:74
6434 "The B<pthread_timedjoin_np>() function performs a join-with-timeout. If "
6435 "I<thread> has not yet terminated, then the call blocks until a maximum time, "
6436 "specified in I<abstime>. If the timeout expires before I<thread> "
6437 "terminates, the call returns an error. The I<abstime> argument is a "
6438 "structure of the following form, specifying an absolute time measured since "
6439 "the Epoch (see B<time>(2)):"
6443 #: build/C/man3/pthread_tryjoin_np.3:81
6446 "struct timespec {\n"
6447 " time_t tv_sec; /* seconds */\n"
6448 " long tv_nsec; /* nanoseconds */\n"
6453 #: build/C/man3/pthread_tryjoin_np.3:87
6454 msgid "On success, these functions return 0; on error, they return an error number."
6458 #: build/C/man3/pthread_tryjoin_np.3:92
6460 "These functions can fail with the same errors as B<pthread_join>(3). "
6461 "B<pthread_tryjoin_np>() can in addition fail with the following error:"
6465 #: build/C/man3/pthread_tryjoin_np.3:92
6471 #: build/C/man3/pthread_tryjoin_np.3:96
6472 msgid "I<thread> had not yet terminated at the time of the call."
6476 #: build/C/man3/pthread_tryjoin_np.3:99
6477 msgid "B<pthread_timedjoin_np>() can in addition fail with the following error:"
6481 #: build/C/man3/pthread_tryjoin_np.3:99
6483 msgid "B<ETIMEDOUT>"
6487 #: build/C/man3/pthread_tryjoin_np.3:104
6488 msgid "The call timed out before I<thread> terminated."
6492 #: build/C/man3/pthread_tryjoin_np.3:108
6493 msgid "B<pthread_timedjoin_np>() never returns the error B<EINTR>."
6497 #: build/C/man3/pthread_tryjoin_np.3:110
6498 msgid "These functions first appeared in glibc in version 2.3.3."
6502 #: build/C/man3/pthread_tryjoin_np.3:115
6503 msgid "The following code waits to join for up to 5 seconds:"
6507 #: build/C/man3/pthread_tryjoin_np.3:119
6510 " struct timespec ts;\n"
6515 #: build/C/man3/pthread_tryjoin_np.3:121
6521 #: build/C/man3/pthread_tryjoin_np.3:125
6524 " if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {\n"
6525 "\t/* Handle error */\n"
6530 #: build/C/man3/pthread_tryjoin_np.3:127
6532 msgid " ts.tv_sec += 5;\n"
6536 #: build/C/man3/pthread_tryjoin_np.3:132
6539 " s = pthread_timedjoin_np(thread, NULL, &ts);\n"
6541 " /* Handle error */\n"
6546 #: build/C/man3/pthread_tryjoin_np.3:137
6547 msgid "B<clock_gettime>(2), B<pthread_exit>(3), B<pthread_join>(3), B<pthreads>(7)"
6551 #: build/C/man3/pthread_yield.3:23
6553 msgid "PTHREAD_YIELD"
6557 #: build/C/man3/pthread_yield.3:26
6558 msgid "pthread_yield - yield the processor"
6562 #: build/C/man3/pthread_yield.3:31
6564 msgid "B<int pthread_yield(void);>\n"
6568 #: build/C/man3/pthread_yield.3:41
6570 "B<pthread_yield>() causes the calling thread to relinquish the CPU. The "
6571 "thread is placed at the end of the run queue for its static priority and "
6572 "another thread is scheduled to run. For further details, see "
6577 #: build/C/man3/pthread_yield.3:46
6579 "On success, B<pthread_yield>() returns 0; on error, it returns an error "
6584 #: build/C/man3/pthread_yield.3:50
6586 "On Linux, this call always succeeds (but portable and future-proof "
6587 "applications should nevertheless handle a possible error return)."
6590 #. e.g., the BSDs, Tru64, AIX, and Irix.
6592 #: build/C/man3/pthread_yield.3:56
6594 "This call is nonstandard, but present on several other systems. Use the "
6595 "standardized B<sched_yield>(2) instead."
6599 #: build/C/man3/pthread_yield.3:59
6600 msgid "On Linux, this function is implemented as a call to B<sched_yield>(2)."
6604 #: build/C/man3/pthread_yield.3:62
6605 msgid "B<sched_setscheduler>(2), B<sched_yield>(2) B<pthreads>(7)"
6609 #: build/C/man7/pthreads.7:24
6615 #: build/C/man7/pthreads.7:24
6621 #: build/C/man7/pthreads.7:27
6622 msgid "pthreads - POSIX threads"
6626 #: build/C/man7/pthreads.7:34
6628 "POSIX.1 specifies a set of interfaces (functions, header files) for threaded "
6629 "programming commonly known as POSIX threads, or Pthreads. A single process "
6630 "can contain multiple threads, all of which are executing the same program. "
6631 "These threads share the same global memory (data and heap segments), but "
6632 "each thread has its own stack (automatic variables)."
6636 #: build/C/man7/pthreads.7:37
6638 "POSIX.1 also requires that threads share a range of other attributes (i.e., "
6639 "these attributes are process-wide rather than per-thread):"
6643 #: build/C/man7/pthreads.7:37 build/C/man7/pthreads.7:39 build/C/man7/pthreads.7:41 build/C/man7/pthreads.7:43 build/C/man7/pthreads.7:45 build/C/man7/pthreads.7:47 build/C/man7/pthreads.7:49 build/C/man7/pthreads.7:52 build/C/man7/pthreads.7:54 build/C/man7/pthreads.7:57 build/C/man7/pthreads.7:63 build/C/man7/pthreads.7:68 build/C/man7/pthreads.7:71 build/C/man7/pthreads.7:74 build/C/man7/pthreads.7:82 build/C/man7/pthreads.7:86 build/C/man7/pthreads.7:89 build/C/man7/pthreads.7:93 build/C/man7/pthreads.7:96 build/C/man7/pthreads.7:103 build/C/man7/pthreads.7:106 build/C/man7/pthreads.7:683 build/C/man7/pthreads.7:690 build/C/man7/pthreads.7:702 build/C/man7/pthreads.7:712 build/C/man7/pthreads.7:716 build/C/man7/pthreads.7:725 build/C/man7/pthreads.7:735 build/C/man7/pthreads.7:742 build/C/man7/pthreads.7:749 build/C/man7/pthreads.7:751 build/C/man7/pthreads.7:754 build/C/man7/pthreads.7:760 build/C/man7/pthreads.7:763 build/C/man7/pthreads.7:765 build/C/man7/pthreads.7:767 build/C/man7/pthreads.7:777 build/C/man7/pthreads.7:797 build/C/man7/pthreads.7:806 build/C/man7/pthreads.7:812 build/C/man7/pthreads.7:814 build/C/man7/pthreads.7:816 build/C/man7/pthreads.7:820 build/C/man7/pthreads.7:825 build/C/man7/pthreads.7:833
6649 #: build/C/man7/pthreads.7:39
6654 #: build/C/man7/pthreads.7:41
6655 msgid "parent process ID"
6659 #: build/C/man7/pthreads.7:43
6660 msgid "process group ID and session ID"
6664 #: build/C/man7/pthreads.7:45
6665 msgid "controlling terminal"
6669 #: build/C/man7/pthreads.7:47
6670 msgid "user and group IDs"
6674 #: build/C/man7/pthreads.7:49
6675 msgid "open file descriptors"
6679 #: build/C/man7/pthreads.7:52
6680 msgid "record locks (see B<fcntl>(2))"
6684 #: build/C/man7/pthreads.7:54
6685 msgid "signal dispositions"
6689 #: build/C/man7/pthreads.7:57
6690 msgid "file mode creation mask (B<umask>(2))"
6694 #: build/C/man7/pthreads.7:63
6695 msgid "current directory (B<chdir>(2)) and root directory (B<chroot>(2))"
6699 #: build/C/man7/pthreads.7:68
6700 msgid "interval timers (B<setitimer>(2)) and POSIX timers (B<timer_create>(2))"
6704 #: build/C/man7/pthreads.7:71
6705 msgid "nice value (B<setpriority>(2))"
6709 #: build/C/man7/pthreads.7:74
6710 msgid "resource limits (B<setrlimit>(2))"
6714 #: build/C/man7/pthreads.7:79
6716 "measurements of the consumption of CPU time (B<times>(2)) and resources "
6721 #: build/C/man7/pthreads.7:82
6723 "As well as the stack, POSIX.1 specifies that various other attributes are "
6724 "distinct for each thread, including:"
6728 #: build/C/man7/pthreads.7:86
6729 msgid "thread ID (the I<pthread_t> data type)"
6733 #: build/C/man7/pthreads.7:89
6734 msgid "signal mask (B<pthread_sigmask>(3))"
6738 #: build/C/man7/pthreads.7:93
6739 msgid "the I<errno> variable"
6743 #: build/C/man7/pthreads.7:96
6744 msgid "alternate signal stack (B<sigaltstack>(2))"
6748 #: build/C/man7/pthreads.7:101
6750 "real-time scheduling policy and priority (B<sched_setscheduler>(2) and "
6751 "B<sched_setparam>(2))"
6755 #: build/C/man7/pthreads.7:103
6756 msgid "The following Linux-specific features are also per-thread:"
6760 #: build/C/man7/pthreads.7:106
6761 msgid "capabilities (see B<capabilities>(7))"
6765 #: build/C/man7/pthreads.7:109
6766 msgid "CPU affinity (B<sched_setaffinity>(2))"
6770 #: build/C/man7/pthreads.7:109
6772 msgid "Pthreads function return values"
6776 #: build/C/man7/pthreads.7:116
6778 "Most pthreads functions return 0 on success, and an error number of "
6779 "failure. Note that the pthreads functions do not set I<errno>. For each of "
6780 "the pthreads functions that can return an error, POSIX.1-2001 specifies that "
6781 "the function can never fail with the error B<EINTR>."
6785 #: build/C/man7/pthreads.7:116
6791 #: build/C/man7/pthreads.7:130
6793 "Each of the threads in a process has a unique thread identifier (stored in "
6794 "the type I<pthread_t>). This identifier is returned to the caller of "
6795 "B<pthread_create>(3), and a thread can obtain its own thread identifier "
6796 "using B<pthread_self>(3). Thread IDs are only guaranteed to be unique "
6797 "within a process. A thread ID may be reused after a terminated thread has "
6798 "been joined, or a detached thread has terminated. In all pthreads functions "
6799 "that accept a thread ID as an argument, that ID by definition refers to a "
6800 "thread in the same process as the caller."
6804 #: build/C/man7/pthreads.7:130
6806 msgid "Thread-safe functions"
6810 #: build/C/man7/pthreads.7:134
6812 "A thread-safe function is one that can be safely (i.e., it will deliver the "
6813 "same results regardless of whether it is) called from multiple threads at "
6818 #: build/C/man7/pthreads.7:138
6820 "POSIX.1-2001 and POSIX.1-2008 require that all functions specified in the "
6821 "standard shall be thread-safe, except for the following functions:"
6825 #: build/C/man7/pthreads.7:232
6832 "ctermid() if passed a non-NULL argument\n"
6846 "ecvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
6851 "fcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
6853 "gcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
6855 "getchar_unlocked()\n"
6861 "gethostbyaddr() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
6862 "gethostbyname() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
6869 "getprotobyname()\n"
6870 "getprotobynumber()\n"
6898 "putchar_unlocked()\n"
6909 "strsignal() [Added in POSIX.1-2008]\n"
6911 "system() [Added in POSIX.1-2008]\n"
6912 "tmpnam() if passed a non-NULL argument\n"
6915 "wcrtomb() if its final argument is NULL\n"
6916 "wcsrtombs() if its final argument is NULL\n"
6922 #: build/C/man7/pthreads.7:234
6924 msgid "Async-cancel-safe functions"
6928 #: build/C/man7/pthreads.7:238
6930 "An async-cancel-safe function is one that can be safely called in an "
6931 "application where asynchronous cancelability is enabled (see "
6932 "B<pthread_setcancelstate>(3))."
6936 #: build/C/man7/pthreads.7:241
6938 "Only the following functions are required to be async-cancel-safe by "
6939 "POSIX.1-2001 and POSIX.1-2008:"
6943 #: build/C/man7/pthreads.7:247
6946 "pthread_cancel()\n"
6947 "pthread_setcancelstate()\n"
6948 "pthread_setcanceltype()\n"
6952 #: build/C/man7/pthreads.7:249
6954 msgid "Cancellation Points"
6958 #: build/C/man7/pthreads.7:256
6960 "POSIX.1 specifies that certain functions must, and certain other functions "
6961 "may, be cancellation points. If a thread is cancelable, its cancelability "
6962 "type is deferred, and a cancellation request is pending for the thread, then "
6963 "the thread is canceled when it calls a function that is a cancellation "
6968 #: build/C/man7/pthreads.7:259
6970 "The following functions are required to be cancellation points by "
6971 "POSIX.1-2001 and/or POSIX.1-2008:"
6975 #: build/C/man7/pthreads.7:322
6980 "clock_nanosleep()\n"
6984 "fcntl() F_SETLKW\n"
6992 "mq_timedreceive()\n"
6999 "openat() [Added in POSIX.1-2008]\n"
7004 "pthread_cond_timedwait()\n"
7005 "pthread_cond_wait()\n"
7007 "pthread_testcancel()\n"
7022 "sigpause() [POSIX.1-2001 only (moves to \"may\" list in POSIX.1-2008)]\n"
7030 "usleep() [POSIX.1-2001 only (function removed in POSIX.1-2008)]\n"
7039 #: build/C/man7/pthreads.7:327
7041 "The following functions may be cancellation points according to POSIX.1-2001 "
7042 "and/or POSIX.1-2008:"
7046 #: build/C/man7/pthreads.7:555
7055 "chmod() [Added in POSIX.1-2008]\n"
7056 "chown() [Added in POSIX.1-2008]\n"
7070 "dprintf() [Added in POSIX.1-2008]\n"
7078 "faccessat() [Added in POSIX.1-2008]\n"
7079 "fchmod() [Added in POSIX.1-2008]\n"
7080 "fchmodat() [Added in POSIX.1-2008]\n"
7081 "fchown() [Added in POSIX.1-2008]\n"
7082 "fchownat() [Added in POSIX.1-2008]\n"
7084 "fcntl() (for any value of cmd argument)\n"
7106 "fstatat() [Added in POSIX.1-2008]\n"
7110 "futimens() [Added in POSIX.1-2008]\n"
7118 "getchar_unlocked()\n"
7121 "getdelim() [Added in POSIX.1-2008]\n"
7127 "gethostbyaddr() [SUSv3 only (function removed in POSIX.1-2008)]\n"
7128 "gethostbyname() [SUSv3 only (function removed in POSIX.1-2008)]\n"
7132 "getline() [Added in POSIX.1-2008]\n"
7139 "getopt() (if opterr is nonzero)\n"
7140 "getprotobyname()\n"
7141 "getprotobynumber()\n"
7157 "getwd() [SUSv3 only (function removed in POSIX.1-2008)]\n"
7163 "linkat() [Added in POSIX.1-2008]\n"
7164 "lio_listio() [Added in POSIX.1-2008]\n"
7167 "lockf() [Added in POSIX.1-2008]\n"
7170 "mkdir() [Added in POSIX.1-2008]\n"
7171 "mkdirat() [Added in POSIX.1-2008]\n"
7172 "mkdtemp() [Added in POSIX.1-2008]\n"
7173 "mkfifo() [Added in POSIX.1-2008]\n"
7174 "mkfifoat() [Added in POSIX.1-2008]\n"
7175 "mknod() [Added in POSIX.1-2008]\n"
7176 "mknodat() [Added in POSIX.1-2008]\n"
7187 "posix_fallocate()\n"
7192 "posix_trace_clear()\n"
7193 "posix_trace_close()\n"
7194 "posix_trace_create()\n"
7195 "posix_trace_create_withlog()\n"
7196 "posix_trace_eventtypelist_getnext_id()\n"
7197 "posix_trace_eventtypelist_rewind()\n"
7198 "posix_trace_flush()\n"
7199 "posix_trace_get_attr()\n"
7200 "posix_trace_get_filter()\n"
7201 "posix_trace_get_status()\n"
7202 "posix_trace_getnext_event()\n"
7203 "posix_trace_open()\n"
7204 "posix_trace_rewind()\n"
7205 "posix_trace_set_filter()\n"
7206 "posix_trace_shutdown()\n"
7207 "posix_trace_timedgetnext_event()\n"
7208 "posix_typed_mem_open()\n"
7210 "psiginfo() [Added in POSIX.1-2008]\n"
7211 "psignal() [Added in POSIX.1-2008]\n"
7212 "pthread_rwlock_rdlock()\n"
7213 "pthread_rwlock_timedrdlock()\n"
7214 "pthread_rwlock_timedwrlock()\n"
7215 "pthread_rwlock_wrlock()\n"
7219 "putchar_unlocked()\n"
7226 "readlink() [Added in POSIX.1-2008]\n"
7227 "readlinkat() [Added in POSIX.1-2008]\n"
7230 "renameat() [Added in POSIX.1-2008]\n"
7233 "scandir() [Added in POSIX.1-2008]\n"
7244 "sigpause() [Added in POSIX.1-2008]\n"
7250 "symlinkat() [Added in POSIX.1-2008]\n"
7261 "unlinkat() [Added in POSIX.1-2008]\n"
7262 "utime() [Added in POSIX.1-2008]\n"
7263 "utimensat() [Added in POSIX.1-2008]\n"
7264 "utimes() [Added in POSIX.1-2008]\n"
7265 "vdprintf() [Added in POSIX.1-2008]\n"
7276 #. So, scanning "cancellation point" comments in the glibc 2.8 header
7277 #. files, it looks as though at least the following nonstandard
7278 #. functions are cancellation points:
7318 #. getprotobynumber_r
7333 #. getwchar_unlocked
7340 #. pthread_timedjoin_np
7346 #. putwchar_unlocked
7367 #: build/C/man7/pthreads.7:653
7369 "An implementation may also mark other functions not specified in the "
7370 "standard as cancellation points. In particular, an implementation is likely "
7371 "to mark any nonstandard function that may block as a cancellation point. "
7372 "(This includes most functions that can touch files.)"
7376 #: build/C/man7/pthreads.7:653
7378 msgid "Compiling on Linux"
7382 #: build/C/man7/pthreads.7:656
7384 "On Linux, programs that use the Pthreads API should be compiled using I<cc "
7389 #: build/C/man7/pthreads.7:656
7391 msgid "Linux Implementations of POSIX Threads"
7395 #: build/C/man7/pthreads.7:659
7397 "Over time, two threading implementations have been provided by the GNU C "
7402 #: build/C/man7/pthreads.7:659
7404 msgid "B<LinuxThreads>"
7408 #: build/C/man7/pthreads.7:663
7410 "This is the original Pthreads implementation. Since glibc 2.4, this "
7411 "implementation is no longer supported."
7415 #: build/C/man7/pthreads.7:663
7417 msgid "B<NPTL> (Native POSIX Threads Library)"
7421 #: build/C/man7/pthreads.7:671
7423 "This is the modern Pthreads implementation. By comparison with "
7424 "LinuxThreads, NPTL provides closer conformance to the requirements of the "
7425 "POSIX.1 specification and better performance when creating large numbers of "
7426 "threads. NPTL is available since glibc 2.3.2, and requires features that "
7427 "are present in the Linux 2.6 kernel."
7431 #: build/C/man7/pthreads.7:681
7433 "Both of these are so-called 1:1 implementations, meaning that each thread "
7434 "maps to a kernel scheduling entity. Both threading implementations employ "
7435 "the Linux B<clone>(2) system call. In NPTL, thread synchronization "
7436 "primitives (mutexes, thread joining, etc.) are implemented using the Linux "
7437 "B<futex>(2) system call."
7441 #: build/C/man7/pthreads.7:681
7443 msgid "LinuxThreads"
7447 #: build/C/man7/pthreads.7:683
7448 msgid "The notable features of this implementation are the following:"
7452 #: build/C/man7/pthreads.7:690
7454 "In addition to the main (initial) thread, and the threads that the program "
7455 "creates using B<pthread_create>(3), the implementation creates a \"manager\" "
7456 "thread. This thread handles thread creation and termination. (Problems can "
7457 "result if this thread is inadvertently killed.)"
7461 #: build/C/man7/pthreads.7:702
7463 "Signals are used internally by the implementation. On Linux 2.2 and later, "
7464 "the first three real-time signals are used (see also B<signal>(7)). On "
7465 "older Linux kernels, B<SIGUSR1> and B<SIGUSR2> are used. Applications must "
7466 "avoid the use of whichever set of signals is employed by the implementation."
7470 #: build/C/man7/pthreads.7:709
7472 "Threads do not share process IDs. (In effect, LinuxThreads threads are "
7473 "implemented as processes which share more information than usual, but which "
7474 "do not share a common process ID.) LinuxThreads threads (including the "
7475 "manager thread) are visible as separate processes using B<ps>(1)."
7479 #: build/C/man7/pthreads.7:712
7481 "The LinuxThreads implementation deviates from the POSIX.1 specification in a "
7482 "number of ways, including the following:"
7486 #: build/C/man7/pthreads.7:716
7487 msgid "Calls to B<getpid>(2) return a different value in each thread."
7491 #: build/C/man7/pthreads.7:725
7493 "Calls to B<getppid>(2) in threads other than the main thread return the "
7494 "process ID of the manager thread; instead B<getppid>(2) in these threads "
7495 "should return the same value as B<getppid>(2) in the main thread."
7499 #: build/C/man7/pthreads.7:735
7501 "When one thread creates a new child process using B<fork>(2), any thread "
7502 "should be able to B<wait>(2) on the child. However, the implementation "
7503 "only allows the thread that created the child to B<wait>(2) on it."
7507 #: build/C/man7/pthreads.7:742
7509 "When a thread calls B<execve>(2), all other threads are terminated (as "
7510 "required by POSIX.1). However, the resulting process has the same PID as "
7511 "the thread that called B<execve>(2): it should have the same PID as the main "
7516 #: build/C/man7/pthreads.7:749
7518 "Threads do not share user and group IDs. This can cause complications with "
7519 "set-user-ID programs and can cause failures in Pthreads functions if an "
7520 "application changes its credentials using B<seteuid>(2) or similar."
7524 #: build/C/man7/pthreads.7:751
7525 msgid "Threads do not share a common session ID and process group ID."
7529 #: build/C/man7/pthreads.7:754
7530 msgid "Threads do not share record locks created using B<fcntl>(2)."
7534 #: build/C/man7/pthreads.7:760
7536 "The information returned by B<times>(2) and B<getrusage>(2) is per-thread "
7537 "rather than process-wide."
7541 #: build/C/man7/pthreads.7:763
7542 msgid "Threads do not share semaphore undo values (see B<semop>(2))."
7546 #: build/C/man7/pthreads.7:765
7547 msgid "Threads do not share interval timers."
7550 #. FIXME . bug report filed for NPTL nice nonconformance
7551 #. http://bugzilla.kernel.org/show_bug.cgi?id=6258
7552 #. Sep 08: there is a patch by Denys Vlasenko to address this
7553 #. "make setpriority POSIX compliant; introduce PRIO_THREAD extension"
7554 #. Monitor this to see if it makes it into mainline.
7556 #: build/C/man7/pthreads.7:767 build/C/man7/pthreads.7:804
7557 msgid "Threads do not share a common nice value."
7561 #: build/C/man7/pthreads.7:777
7563 "POSIX.1 distinguishes the notions of signals that are directed to the "
7564 "process as a whole and signals that are directed to individual threads. "
7565 "According to POSIX.1, a process-directed signal (sent using B<kill>(2), for "
7566 "example) should be handled by a single, arbitrarily selected thread within "
7567 "the process. LinuxThreads does not support the notion of process-directed "
7568 "signals: signals may only be sent to specific threads."
7572 #: build/C/man7/pthreads.7:786
7574 "Threads have distinct alternate signal stack settings. However, a new "
7575 "thread's alternate signal stack settings are copied from the thread that "
7576 "created it, so that the threads initially share an alternate signal stack. "
7577 "(A new thread should start with no alternate signal stack defined. If two "
7578 "threads handle signals on their shared alternate signal stack at the same "
7579 "time, unpredictable program failures are likely to occur.)"
7583 #: build/C/man7/pthreads.7:786
7589 #: build/C/man7/pthreads.7:795
7591 "With NPTL, all of the threads in a process are placed in the same thread "
7592 "group; all members of a thread group share the same PID. NPTL does not "
7593 "employ a manager thread. NPTL makes internal use of the first two real-time "
7594 "signals (see also B<signal>(7)); these signals cannot be used in "
7599 #: build/C/man7/pthreads.7:797
7600 msgid "NPTL still has at least one nonconformance with POSIX.1:"
7604 #: build/C/man7/pthreads.7:806
7605 msgid "Some NPTL nonconformances only occur with older kernels:"
7609 #: build/C/man7/pthreads.7:812
7611 "The information returned by B<times>(2) and B<getrusage>(2) is per-thread "
7612 "rather than process-wide (fixed in kernel 2.6.9)."
7616 #: build/C/man7/pthreads.7:814
7617 msgid "Threads do not share resource limits (fixed in kernel 2.6.10)."
7621 #: build/C/man7/pthreads.7:816
7622 msgid "Threads do not share interval timers (fixed in kernel 2.6.12)."
7626 #: build/C/man7/pthreads.7:820
7628 "Only the main thread is permitted to start a new session using B<setsid>(2) "
7629 "(fixed in kernel 2.6.16)."
7633 #: build/C/man7/pthreads.7:825
7635 "Only the main thread is permitted to make the process into a process group "
7636 "leader using B<setpgid>(2) (fixed in kernel 2.6.16)."
7640 #: build/C/man7/pthreads.7:831
7642 "Threads have distinct alternate signal stack settings. However, a new "
7643 "thread's alternate signal stack settings are copied from the thread that "
7644 "created it, so that the threads initially share an alternate signal stack "
7645 "(fixed in kernel 2.6.16)."
7649 #: build/C/man7/pthreads.7:833
7650 msgid "Note the following further points about the NPTL implementation:"
7654 #: build/C/man7/pthreads.7:847
7656 "If the stack size soft resource limit (see the description of "
7657 "B<RLIMIT_STACK> in B<setrlimit>(2)) is set to a value other than "
7658 "I<unlimited>, then this value defines the default stack size for new "
7659 "threads. To be effective, this limit must be set before the program is "
7660 "executed, perhaps using the I<ulimit -s> shell built-in command (I<limit "
7661 "stacksize> in the C shell)."
7665 #: build/C/man7/pthreads.7:847
7667 msgid "Determining the Threading Implementation"
7671 #: build/C/man7/pthreads.7:852
7673 "Since glibc 2.3.2, the B<getconf>(1) command can be used to determine the "
7674 "system's threading implementation, for example:"
7678 #: build/C/man7/pthreads.7:857
7681 "bash$ getconf GNU_LIBPTHREAD_VERSION\n"
7686 #: build/C/man7/pthreads.7:862
7688 "With older glibc versions, a command such as the following should be "
7689 "sufficient to determine the default threading implementation:"
7693 #: build/C/man7/pthreads.7:868
7696 "bash$ $( ldd /bin/ls | grep libc.so | awk \\(aq{print $3}\\(aq ) | \\e\n"
7697 " egrep -i \\(aqthreads|nptl\\(aq\n"
7698 " Native POSIX Threads Library by Ulrich Drepper et al\n"
7702 #: build/C/man7/pthreads.7:870
7704 msgid "Selecting the Threading Implementation: LD_ASSUME_KERNEL"
7708 #: build/C/man7/pthreads.7:885
7710 "On systems with a glibc that supports both LinuxThreads and NPTL (i.e., "
7711 "glibc 2.3.I<x>), the B<LD_ASSUME_KERNEL> environment variable can be used to "
7712 "override the dynamic linker's default choice of threading implementation. "
7713 "This variable tells the dynamic linker to assume that it is running on top "
7714 "of a particular kernel version. By specifying a kernel version that does "
7715 "not provide the support required by NPTL, we can force the use of "
7716 "LinuxThreads. (The most likely reason for doing this is to run a (broken) "
7717 "application that depends on some nonconformant behavior in LinuxThreads.) "
7722 #: build/C/man7/pthreads.7:891
7725 "bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \\e\n"
7726 " awk \\(aq{print $3}\\(aq ) | egrep -i "
7727 "\\(aqthreads|ntpl\\(aq\n"
7728 " linuxthreads-0.10 by Xavier Leroy\n"
7732 #: build/C/man7/pthreads.7:903
7734 "B<clone>(2), B<futex>(2), B<gettid>(2), B<proc>(5), B<futex>(7), "
7735 "B<sigevent>(7), B<signal>(7),"
7739 #: build/C/man7/pthreads.7:926
7741 "and various Pthreads manual pages, for example: B<pthread_attr_init>(3), "
7742 "B<pthread_atfork>(3), B<pthread_cancel>(3), B<pthread_cleanup_push>(3), "
7743 "B<pthread_cond_signal>(3), B<pthread_cond_wait>(3), B<pthread_create>(3), "
7744 "B<pthread_detach>(3), B<pthread_equal>(3), B<pthread_exit>(3), "
7745 "B<pthread_key_create>(3), B<pthread_kill>(3), B<pthread_mutex_lock>(3), "
7746 "B<pthread_mutex_unlock>(3), B<pthread_once>(3), "
7747 "B<pthread_setcancelstate>(3), B<pthread_setcanceltype>(3), "
7748 "B<pthread_setspecific>(3), B<pthread_sigmask>(3), B<pthread_sigqueue>(3), "
7749 "and B<pthread_testcancel>(3)"