x86-64: Add log2f with FMA
[glibc.git] / manual / threads.texi
blob769d974d504c54a1893b5b3d3db80989059390b2
1 @node POSIX Threads
2 @c @node POSIX Threads, Internal Probes, Cryptographic Functions, Top
3 @chapter POSIX Threads
4 @c %MENU% POSIX Threads
5 @cindex pthreads
7 This chapter describes the @glibcadj{} POSIX Threads implementation.
9 @menu
10 * Thread-specific Data::          Support for creating and
11                                   managing thread-specific data
12 * Non-POSIX Extensions::          Additional functions to extend
13                                   POSIX Thread functionality
14 @end menu
16 @node Thread-specific Data
17 @section Thread-specific Data
19 The @glibcadj{} implements functions to allow users to create and manage
20 data specific to a thread.  Such data may be destroyed at thread exit,
21 if a destructor is provided.  The following functions are defined:
23 @deftypefun int pthread_key_create (pthread_key_t *@var{key}, void (*@var{destructor})(void*))
24 @standards{POSIX, pthread.h}
25 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
26 @c pthread_key_create ok
27 @c  KEY_UNUSED ok
28 @c  KEY_USABLE ok
29 Create a thread-specific data key for the calling thread, referenced by
30 @var{key}.
32 Objects declared with the C++11 @code{thread_local} keyword are destroyed
33 before thread-specific data, so they should not be used in thread-specific
34 data destructors or even as members of the thread-specific data, since the
35 latter is passed as an argument to the destructor function.
36 @end deftypefun
38 @deftypefun int pthread_key_delete (pthread_key_t @var{key})
39 @standards{POSIX, pthread.h}
40 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
41 @c pthread_key_delete ok
42 @c   This uses atomic compare and exchange to increment the seq number
43 @c   after testing it's not a KEY_UNUSED seq number.
44 @c  KEY_UNUSED dup ok
45 Destroy the thread-specific data @var{key} in the calling thread.  The
46 destructor for the thread-specific data is not called during destruction, nor
47 is it called during thread exit.
48 @end deftypefun
50 @deftypefun void *pthread_getspecific (pthread_key_t @var{key})
51 @standards{POSIX, pthread.h}
52 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
53 @c pthread_getspecific ok
54 Return the thread-specific data associated with @var{key} in the calling
55 thread.
56 @end deftypefun
58 @deftypefun int pthread_setspecific (pthread_key_t @var{key}, const void *@var{value})
59 @standards{POSIX, pthread.h}
60 @safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @acsmem{}}}
61 @c pthread_setspecific @asucorrupt @ascuheap @acucorrupt @acsmem
62 @c   a level2 block may be allocated by a signal handler after
63 @c   another call already made a decision to allocate it, thus losing
64 @c   the allocated value.  the seq number is updated before the
65 @c   value, which might cause an earlier-generation value to seem
66 @c   current if setspecific is cancelled or interrupted by a signal
67 @c  KEY_UNUSED ok
68 @c  calloc dup @ascuheap @acsmem
69 Associate the thread-specific @var{value} with @var{key} in the calling thread.
70 @end deftypefun
73 @node Non-POSIX Extensions
74 @section Non-POSIX Extensions
76 In addition to implementing the POSIX API for threads, @theglibc{} provides
77 additional functions and interfaces to provide functionality not specified in
78 the standard.
80 @menu
81 * Default Thread Attributes::             Setting default attributes for
82                                           threads in a process.
83 @end menu
85 @node Default Thread Attributes
86 @subsection Setting Process-wide defaults for thread attributes
88 @Theglibc{} provides non-standard API functions to set and get the default
89 attributes used in the creation of threads in a process.
91 @deftypefun int pthread_getattr_default_np (pthread_attr_t *@var{attr})
92 @standards{GNU, pthread.h}
93 @safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
94 @c Takes lock around read from default_pthread_attr.
95 Get the default attribute values and set @var{attr} to match.  This
96 function returns @math{0} on success and a non-zero error code on
97 failure.
98 @end deftypefun
100 @deftypefun int pthread_setattr_default_np (pthread_attr_t *@var{attr})
101 @standards{GNU, pthread.h}
102 @safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsmem{}}}
103 @c pthread_setattr_default_np @ascuheap @asulock @aculock @acsmem
104 @c  check_sched_policy_attr ok
105 @c  check_sched_priority_attr ok
106 @c   sched_get_priority_min dup ok
107 @c   sched_get_priority_max dup ok
108 @c  check_stacksize_attr ok
109 @c  lll_lock @asulock @aculock
110 @c  free dup @ascuheap @acsmem
111 @c  realloc dup @ascuheap @acsmem
112 @c  memcpy dup ok
113 @c  lll_unlock @asulock @aculock
114 Set the default attribute values to match the values in @var{attr}.  The
115 function returns @math{0} on success and a non-zero error code on failure.
116 The following error codes are defined for this function:
118 @table @code
119 @item EINVAL
120 At least one of the values in @var{attr} does not qualify as valid for the
121 attributes or the stack address is set in the attribute.
122 @item ENOMEM
123 The system does not have sufficient memory.
124 @end table
125 @end deftypefun
127 @c FIXME these are undocumented:
128 @c pthread_atfork
129 @c pthread_attr_destroy
130 @c pthread_attr_getaffinity_np
131 @c pthread_attr_getdetachstate
132 @c pthread_attr_getguardsize
133 @c pthread_attr_getinheritsched
134 @c pthread_attr_getschedparam
135 @c pthread_attr_getschedpolicy
136 @c pthread_attr_getscope
137 @c pthread_attr_getstack
138 @c pthread_attr_getstackaddr
139 @c pthread_attr_getstacksize
140 @c pthread_attr_init
141 @c pthread_attr_setaffinity_np
142 @c pthread_attr_setdetachstate
143 @c pthread_attr_setguardsize
144 @c pthread_attr_setinheritsched
145 @c pthread_attr_setschedparam
146 @c pthread_attr_setschedpolicy
147 @c pthread_attr_setscope
148 @c pthread_attr_setstack
149 @c pthread_attr_setstackaddr
150 @c pthread_attr_setstacksize
151 @c pthread_barrierattr_destroy
152 @c pthread_barrierattr_getpshared
153 @c pthread_barrierattr_init
154 @c pthread_barrierattr_setpshared
155 @c pthread_barrier_destroy
156 @c pthread_barrier_init
157 @c pthread_barrier_wait
158 @c pthread_cancel
159 @c pthread_cleanup_push
160 @c pthread_cleanup_pop
161 @c pthread_condattr_destroy
162 @c pthread_condattr_getclock
163 @c pthread_condattr_getpshared
164 @c pthread_condattr_init
165 @c pthread_condattr_setclock
166 @c pthread_condattr_setpshared
167 @c pthread_cond_broadcast
168 @c pthread_cond_destroy
169 @c pthread_cond_init
170 @c pthread_cond_signal
171 @c pthread_cond_timedwait
172 @c pthread_cond_wait
173 @c pthread_create
174 @c pthread_detach
175 @c pthread_equal
176 @c pthread_exit
177 @c pthread_getaffinity_np
178 @c pthread_getattr_np
179 @c pthread_getconcurrency
180 @c pthread_getcpuclockid
181 @c pthread_getname_np
182 @c pthread_getschedparam
183 @c pthread_join
184 @c pthread_kill
185 @c pthread_kill_other_threads_np
186 @c pthread_mutexattr_destroy
187 @c pthread_mutexattr_getkind_np
188 @c pthread_mutexattr_getprioceiling
189 @c pthread_mutexattr_getprotocol
190 @c pthread_mutexattr_getpshared
191 @c pthread_mutexattr_getrobust
192 @c pthread_mutexattr_getrobust_np
193 @c pthread_mutexattr_gettype
194 @c pthread_mutexattr_init
195 @c pthread_mutexattr_setkind_np
196 @c pthread_mutexattr_setprioceiling
197 @c pthread_mutexattr_setprotocol
198 @c pthread_mutexattr_setpshared
199 @c pthread_mutexattr_setrobust
200 @c pthread_mutexattr_setrobust_np
201 @c pthread_mutexattr_settype
202 @c pthread_mutex_consistent
203 @c pthread_mutex_consistent_np
204 @c pthread_mutex_destroy
205 @c pthread_mutex_getprioceiling
206 @c pthread_mutex_init
207 @c pthread_mutex_lock
208 @c pthread_mutex_setprioceiling
209 @c pthread_mutex_timedlock
210 @c pthread_mutex_trylock
211 @c pthread_mutex_unlock
212 @c pthread_once
213 @c pthread_rwlockattr_destroy
214 @c pthread_rwlockattr_getkind_np
215 @c pthread_rwlockattr_getpshared
216 @c pthread_rwlockattr_init
217 @c pthread_rwlockattr_setkind_np
218 @c pthread_rwlockattr_setpshared
219 @c pthread_rwlock_destroy
220 @c pthread_rwlock_init
221 @c pthread_rwlock_rdlock
222 @c pthread_rwlock_timedrdlock
223 @c pthread_rwlock_timedwrlock
224 @c pthread_rwlock_tryrdlock
225 @c pthread_rwlock_trywrlock
226 @c pthread_rwlock_unlock
227 @c pthread_rwlock_wrlock
228 @c pthread_self
229 @c pthread_setaffinity_np
230 @c pthread_setcancelstate
231 @c pthread_setcanceltype
232 @c pthread_setconcurrency
233 @c pthread_setname_np
234 @c pthread_setschedparam
235 @c pthread_setschedprio
236 @c pthread_sigmask
237 @c pthread_sigqueue
238 @c pthread_spin_destroy
239 @c pthread_spin_init
240 @c pthread_spin_lock
241 @c pthread_spin_trylock
242 @c pthread_spin_unlock
243 @c pthread_testcancel
244 @c pthread_timedjoin_np
245 @c pthread_tryjoin_np
246 @c pthread_yield