2 @c @node POSIX Threads, Internal Probes, Cryptographic Functions, Top
4 @c %MENU% POSIX Threads
7 This chapter describes the @glibcadj{} POSIX Thread implementation.
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
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 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
25 @c pthread_key_create ok
28 Create a thread-specific data key for the calling thread, referenced by
31 Objects declared with the C++11 @code{thread_local} keyword are destroyed
32 before thread-specific data, so they should not be used in thread-specific
33 data destructors or even as members of the thread-specific data, since the
34 latter is passed as an argument to the destructor function.
37 @deftypefun int pthread_key_delete (pthread_key_t @var{key})
38 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
39 @c pthread_key_delete ok
40 @c This uses atomic compare and exchange to increment the seq number
41 @c after testing it's not a KEY_UNUSED seq number.
43 Destroy the thread-specific data @var{key} in the calling thread. The
44 destructor for the thread-specific data is not called during destruction, nor
45 is it called during thread exit.
48 @deftypefun void *pthread_getspecific (pthread_key_t @var{key})
49 @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
50 @c pthread_getspecific ok
51 Return the thread-specific data associated with @var{key} in the calling
55 @deftypefun int pthread_setspecific (pthread_key_t @var{key}, const void *@var{value})
56 @safety{@prelim{}@mtsafe{}@asunsafe{@asucorrupt{} @ascuheap{}}@acunsafe{@acucorrupt{} @acsmem{}}}
57 @c pthread_setspecific @asucorrupt @ascuheap @acucorrupt @acsmem
58 @c a level2 block may be allocated by a signal handler after
59 @c another call already made a decision to allocate it, thus losing
60 @c the allocated value. the seq number is updated before the
61 @c value, which might cause an earlier-generation value to seem
62 @c current if setspecific is cancelled or interrupted by a signal
64 @c calloc dup @ascuheap @acsmem
65 Associate the thread-specific @var{value} with @var{key} in the calling thread.
69 @node Non-POSIX Extensions
70 @section Non-POSIX Extensions
72 In addition to implementing the POSIX API for threads, @theglibc{} provides
73 additional functions and interfaces to provide functionality not specified in
77 * Default Thread Attributes:: Setting default attributes for
81 @node Default Thread Attributes
82 @subsection Setting Process-wide defaults for thread attributes
84 @Theglibc{} provides non-standard API functions to set and get the default
85 attributes used in the creation of threads in a process.
87 @deftypefun int pthread_getattr_default_np (pthread_attr_t *@var{attr})
88 @safety{@prelim{}@mtsafe{}@asunsafe{@asulock{}}@acunsafe{@aculock{}}}
89 @c Takes lock around read from default_pthread_attr.
90 Get the default attribute values and set @var{attr} to match. This
91 function returns @math{0} on success and a non-zero error code on
95 @deftypefun int pthread_setattr_default_np (pthread_attr_t *@var{attr})
96 @safety{@prelim{}@mtsafe{}@asunsafe{@ascuheap{} @asulock{}}@acunsafe{@aculock{} @acsmem{}}}
97 @c pthread_setattr_default_np @ascuheap @asulock @aculock @acsmem
98 @c check_sched_policy_attr ok
99 @c check_sched_priority_attr ok
100 @c sched_get_priority_min dup ok
101 @c sched_get_priority_max dup ok
102 @c check_cpuset_attr ok
103 @c determine_cpumask_size ok
104 @c check_stacksize_attr ok
105 @c lll_lock @asulock @aculock
106 @c free dup @ascuheap @acsmem
107 @c realloc dup @ascuheap @acsmem
109 @c lll_unlock @asulock @aculock
110 Set the default attribute values to match the values in @var{attr}. The
111 function returns @math{0} on success and a non-zero error code on failure.
112 The following error codes are defined for this function:
116 At least one of the values in @var{attr} does not qualify as valid for the
117 attributes or the stack address is set in the attribute.
119 The system does not have sufficient memory.
123 @c FIXME these are undocumented:
125 @c pthread_attr_destroy
126 @c pthread_attr_getaffinity_np
127 @c pthread_attr_getdetachstate
128 @c pthread_attr_getguardsize
129 @c pthread_attr_getinheritsched
130 @c pthread_attr_getschedparam
131 @c pthread_attr_getschedpolicy
132 @c pthread_attr_getscope
133 @c pthread_attr_getstack
134 @c pthread_attr_getstackaddr
135 @c pthread_attr_getstacksize
137 @c pthread_attr_setaffinity_np
138 @c pthread_attr_setdetachstate
139 @c pthread_attr_setguardsize
140 @c pthread_attr_setinheritsched
141 @c pthread_attr_setschedparam
142 @c pthread_attr_setschedpolicy
143 @c pthread_attr_setscope
144 @c pthread_attr_setstack
145 @c pthread_attr_setstackaddr
146 @c pthread_attr_setstacksize
147 @c pthread_barrierattr_destroy
148 @c pthread_barrierattr_getpshared
149 @c pthread_barrierattr_init
150 @c pthread_barrierattr_setpshared
151 @c pthread_barrier_destroy
152 @c pthread_barrier_init
153 @c pthread_barrier_wait
155 @c pthread_cleanup_push
156 @c pthread_cleanup_pop
157 @c pthread_condattr_destroy
158 @c pthread_condattr_getclock
159 @c pthread_condattr_getpshared
160 @c pthread_condattr_init
161 @c pthread_condattr_setclock
162 @c pthread_condattr_setpshared
163 @c pthread_cond_broadcast
164 @c pthread_cond_destroy
166 @c pthread_cond_signal
167 @c pthread_cond_timedwait
173 @c pthread_getaffinity_np
174 @c pthread_getattr_np
175 @c pthread_getconcurrency
176 @c pthread_getcpuclockid
177 @c pthread_getname_np
178 @c pthread_getschedparam
181 @c pthread_kill_other_threads_np
182 @c pthread_mutexattr_destroy
183 @c pthread_mutexattr_getkind_np
184 @c pthread_mutexattr_getprioceiling
185 @c pthread_mutexattr_getprotocol
186 @c pthread_mutexattr_getpshared
187 @c pthread_mutexattr_getrobust
188 @c pthread_mutexattr_getrobust_np
189 @c pthread_mutexattr_gettype
190 @c pthread_mutexattr_init
191 @c pthread_mutexattr_setkind_np
192 @c pthread_mutexattr_setprioceiling
193 @c pthread_mutexattr_setprotocol
194 @c pthread_mutexattr_setpshared
195 @c pthread_mutexattr_setrobust
196 @c pthread_mutexattr_setrobust_np
197 @c pthread_mutexattr_settype
198 @c pthread_mutex_consistent
199 @c pthread_mutex_consistent_np
200 @c pthread_mutex_destroy
201 @c pthread_mutex_getprioceiling
202 @c pthread_mutex_init
203 @c pthread_mutex_lock
204 @c pthread_mutex_setprioceiling
205 @c pthread_mutex_timedlock
206 @c pthread_mutex_trylock
207 @c pthread_mutex_unlock
209 @c pthread_rwlockattr_destroy
210 @c pthread_rwlockattr_getkind_np
211 @c pthread_rwlockattr_getpshared
212 @c pthread_rwlockattr_init
213 @c pthread_rwlockattr_setkind_np
214 @c pthread_rwlockattr_setpshared
215 @c pthread_rwlock_destroy
216 @c pthread_rwlock_init
217 @c pthread_rwlock_rdlock
218 @c pthread_rwlock_timedrdlock
219 @c pthread_rwlock_timedwrlock
220 @c pthread_rwlock_tryrdlock
221 @c pthread_rwlock_trywrlock
222 @c pthread_rwlock_unlock
223 @c pthread_rwlock_wrlock
225 @c pthread_setaffinity_np
226 @c pthread_setcancelstate
227 @c pthread_setcanceltype
228 @c pthread_setconcurrency
229 @c pthread_setname_np
230 @c pthread_setschedparam
231 @c pthread_setschedprio
234 @c pthread_spin_destroy
237 @c pthread_spin_trylock
238 @c pthread_spin_unlock
239 @c pthread_testcancel
240 @c pthread_timedjoin_np
241 @c pthread_tryjoin_np