1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
<table class="head">
<tr>
<td class="head-ltitle">PTHREAD(3)</td>
<td class="head-vol">Library Functions Manual</td>
<td class="head-rtitle">PTHREAD(3)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">pthread</code> — <span class="Nd">POSIX
thread functions</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="LIBRARY"><a class="permalink" href="#LIBRARY">LIBRARY</a></h1>
<p class="Pp"><span class="Lb">POSIX Threads Library (libpthread,
-lpthread)</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">pthread.h</a>></code></p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">POSIX threads are a set of functions that support applications
with requirements for multiple flows of control, called
<a class="permalink" href="#threads"><i class="Em" id="threads">threads</i></a>,
within a process. Multithreading is used to improve the performance of a
program.</p>
<p class="Pp">The POSIX thread functions are summarized in this section in the
following groups:</p>
<p class="Pp"></p>
<ul class="Bl-bullet Bd-indent Bl-compact">
<li>Thread Routines</li>
<li>Attribute Object Routines</li>
<li>Mutex Routines</li>
<li>Condition Variable Routines</li>
<li>Read/Write Lock Routines</li>
<li>Per-Thread Context Routines</li>
<li>Cleanup Routines</li>
</ul>
<p class="Pp"><span class="Ux">FreeBSD</span> extensions to the POSIX thread
functions are summarized in <a class="Xr">pthread_np(3)</a>.</p>
<section class="Ss">
<h2 class="Ss" id="Thread_Routines"><a class="permalink" href="#Thread_Routines">Thread
Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_create"><var class="Ft">int</var>
<a class="permalink" href="#pthread_create"><code class="Fn">pthread_create</code></a>(<var class="Fa">pthread_t
*thread</var>, <var class="Fa">const pthread_attr_t *attr</var>,
<var class="Fa">void *(*start_routine)(void *)</var>, <var class="Fa">void
*arg</var>);</dt>
<dd>Creates a new thread of execution.</dd>
<dt id="pthread_cancel"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cancel"><code class="Fn">pthread_cancel</code></a>(<var class="Fa">pthread_t
thread</var>)</dt>
<dd>Cancels execution of a thread.</dd>
<dt id="pthread_detach"><var class="Ft">int</var>
<a class="permalink" href="#pthread_detach"><code class="Fn">pthread_detach</code></a>(<var class="Fa">pthread_t
thread</var>)</dt>
<dd>Marks a thread for deletion.</dd>
<dt id="pthread_equal"><var class="Ft">int</var>
<a class="permalink" href="#pthread_equal"><code class="Fn">pthread_equal</code></a>(<var class="Fa">pthread_t
t1</var>, <var class="Fa">pthread_t t2</var>)</dt>
<dd>Compares two thread IDs.</dd>
<dt id="pthread_exit"><var class="Ft">void</var>
<a class="permalink" href="#pthread_exit"><code class="Fn">pthread_exit</code></a>(<var class="Fa">void
*value_ptr</var>)</dt>
<dd>Terminates the calling thread.</dd>
<dt id="pthread_join"><var class="Ft">int</var>
<a class="permalink" href="#pthread_join"><code class="Fn">pthread_join</code></a>(<var class="Fa">pthread_t
thread</var>, <var class="Fa">void **value_ptr</var>)</dt>
<dd>Causes the calling thread to wait for the termination of the specified
thread.</dd>
<dt id="pthread_kill"><var class="Ft">int</var>
<a class="permalink" href="#pthread_kill"><code class="Fn">pthread_kill</code></a>(<var class="Fa">pthread_t
thread</var>, <var class="Fa">int sig</var>)</dt>
<dd>Delivers a signal to a specified thread.</dd>
<dt id="pthread_once"><var class="Ft">int</var>
<a class="permalink" href="#pthread_once"><code class="Fn">pthread_once</code></a>(<var class="Fa">pthread_once_t
*once_control</var>, <var class="Fa">void (*init_routine)(void)</var>)</dt>
<dd>Calls an initialization routine once.</dd>
<dt id="pthread_self"><var class="Ft">pthread_t</var>
<a class="permalink" href="#pthread_self"><code class="Fn">pthread_self</code></a>(<var class="Fa">void</var>)</dt>
<dd>Returns the thread ID of the calling thread.</dd>
<dt id="pthread_setcancelstate"><var class="Ft">int</var>
<a class="permalink" href="#pthread_setcancelstate"><code class="Fn">pthread_setcancelstate</code></a>(<var class="Fa">int
state</var>, <var class="Fa">int *oldstate</var>)</dt>
<dd>Sets the current thread's cancelability state.</dd>
<dt id="pthread_setcanceltype"><var class="Ft">int</var>
<a class="permalink" href="#pthread_setcanceltype"><code class="Fn">pthread_setcanceltype</code></a>(<var class="Fa">int
type</var>, <var class="Fa">int *oldtype</var>)</dt>
<dd>Sets the current thread's cancelability type.</dd>
<dt id="pthread_testcancel"><var class="Ft">void</var>
<a class="permalink" href="#pthread_testcancel"><code class="Fn">pthread_testcancel</code></a>(<var class="Fa">void</var>)</dt>
<dd>Creates a cancellation point in the calling thread.</dd>
<dt id="pthread_yield"><var class="Ft">void</var>
<a class="permalink" href="#pthread_yield"><code class="Fn">pthread_yield</code></a>(<var class="Fa">void</var>)</dt>
<dd>Allows the scheduler to run another thread instead of the current
one.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Attribute_Object_Routines"><a class="permalink" href="#Attribute_Object_Routines">Attribute
Object Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_attr_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_destroy"><code class="Fn">pthread_attr_destroy</code></a>(<var class="Fa">pthread_attr_t
*attr</var>)</dt>
<dd>Destroy a thread attributes object.</dd>
<dt id="pthread_attr_getinheritsched"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getinheritsched"><code class="Fn">pthread_attr_getinheritsched</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">int *inheritsched</var>);</dt>
<dd>Get the inherit scheduling attribute from a thread attributes object.</dd>
<dt id="pthread_attr_getschedparam"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getschedparam"><code class="Fn">pthread_attr_getschedparam</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">struct sched_param
*param</var>);</dt>
<dd>Get the scheduling parameter attribute from a thread attributes
object.</dd>
<dt id="pthread_attr_getschedpolicy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getschedpolicy"><code class="Fn">pthread_attr_getschedpolicy</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">int *policy</var>)</dt>
<dd>Get the scheduling policy attribute from a thread attributes object.</dd>
<dt id="pthread_attr_getscope"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getscope"><code class="Fn">pthread_attr_getscope</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">int *contentionscope</var>)</dt>
<dd>Get the contention scope attribute from a thread attributes object.</dd>
<dt id="pthread_attr_getstacksize"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getstacksize"><code class="Fn">pthread_attr_getstacksize</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">size_t *stacksize</var>)</dt>
<dd>Get the stack size attribute from a thread attributes object.</dd>
<dt id="pthread_attr_getstackaddr"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getstackaddr"><code class="Fn">pthread_attr_getstackaddr</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">void **stackaddr</var>)</dt>
<dd>Get the stack address attribute from a thread attributes object.</dd>
<dt id="pthread_attr_getdetachstate"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_getdetachstate"><code class="Fn">pthread_attr_getdetachstate</code></a>(<var class="Fa">const
pthread_attr_t *attr</var>, <var class="Fa">int *detachstate</var>)</dt>
<dd>Get the detach state attribute from a thread attributes object.</dd>
<dt id="pthread_attr_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_init"><code class="Fn">pthread_attr_init</code></a>(<var class="Fa">pthread_attr_t
*attr</var>)</dt>
<dd>Initialize a thread attributes object with default values.</dd>
<dt id="pthread_attr_setinheritsched"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setinheritsched"><code class="Fn">pthread_attr_setinheritsched</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">int inheritsched</var>)</dt>
<dd>Set the inherit scheduling attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setschedparam"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setschedparam"><code class="Fn">pthread_attr_setschedparam</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">const struct sched_param *param</var>);</dt>
<dd>Set the scheduling parameter attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setschedpolicy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setschedpolicy"><code class="Fn">pthread_attr_setschedpolicy</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">int policy</var>)</dt>
<dd>Set the scheduling policy attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setscope"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setscope"><code class="Fn">pthread_attr_setscope</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">int contentionscope</var>)</dt>
<dd>Set the contention scope attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setstacksize"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setstacksize"><code class="Fn">pthread_attr_setstacksize</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">size_t stacksize</var>)</dt>
<dd>Set the stack size attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setstackaddr"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setstackaddr"><code class="Fn">pthread_attr_setstackaddr</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">void *stackaddr</var>)</dt>
<dd>Set the stack address attribute in a thread attributes object.</dd>
<dt id="pthread_attr_setdetachstate"><var class="Ft">int</var>
<a class="permalink" href="#pthread_attr_setdetachstate"><code class="Fn">pthread_attr_setdetachstate</code></a>(<var class="Fa">pthread_attr_t
*attr</var>, <var class="Fa">int detachstate</var>)</dt>
<dd>Set the detach state in a thread attributes object.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Mutex_Routines"><a class="permalink" href="#Mutex_Routines">Mutex
Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_mutexattr_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_destroy"><code class="Fn">pthread_mutexattr_destroy</code></a>(<var class="Fa">pthread_mutexattr_t
*attr</var>)</dt>
<dd>Destroy a mutex attributes object.</dd>
<dt id="pthread_mutexattr_getprioceiling"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_getprioceiling"><code class="Fn">pthread_mutexattr_getprioceiling</code></a>(<var class="Fa">const
pthread_mutexattr_t *restrict attr</var>, <var class="Fa">int *restrict
ceiling</var>)</dt>
<dd>Obtain priority ceiling attribute of mutex attribute object.</dd>
<dt id="pthread_mutexattr_getprotocol"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_getprotocol"><code class="Fn">pthread_mutexattr_getprotocol</code></a>(<var class="Fa">const
pthread_mutexattr_t *restrict attr</var>, <var class="Fa">int *restrict
protocol</var>)</dt>
<dd>Obtain protocol attribute of mutex attribute object.</dd>
<dt id="pthread_mutexattr_gettype"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_gettype"><code class="Fn">pthread_mutexattr_gettype</code></a>(<var class="Fa">const
pthread_mutexattr_t *restrict attr</var>, <var class="Fa">int *restrict
type</var>)</dt>
<dd>Obtain the mutex type attribute in the specified mutex attributes
object.</dd>
<dt id="pthread_mutexattr_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_init"><code class="Fn">pthread_mutexattr_init</code></a>(<var class="Fa">pthread_mutexattr_t
*attr</var>)</dt>
<dd>Initialize a mutex attributes object with default values.</dd>
<dt id="pthread_mutexattr_setprioceiling"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_setprioceiling"><code class="Fn">pthread_mutexattr_setprioceiling</code></a>(<var class="Fa">pthread_mutexattr_t
*attr</var>, <var class="Fa">int ceiling</var>)</dt>
<dd>Set priority ceiling attribute of mutex attribute object.</dd>
<dt id="pthread_mutexattr_setprotocol"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_setprotocol"><code class="Fn">pthread_mutexattr_setprotocol</code></a>(<var class="Fa">pthread_mutexattr_t
*attr</var>, <var class="Fa">int protocol</var>)</dt>
<dd>Set protocol attribute of mutex attribute object.</dd>
<dt id="pthread_mutexattr_settype"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutexattr_settype"><code class="Fn">pthread_mutexattr_settype</code></a>(<var class="Fa">pthread_mutexattr_t
*attr</var>, <var class="Fa">int type</var>)</dt>
<dd>Set the mutex type attribute that is used when a mutex is created.</dd>
<dt id="pthread_mutex_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_destroy"><code class="Fn">pthread_mutex_destroy</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>)</dt>
<dd>Destroy a mutex.</dd>
<dt id="pthread_mutex_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_init"><code class="Fn">pthread_mutex_init</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>, <var class="Fa">const pthread_mutexattr_t *attr</var>);</dt>
<dd>Initialize a mutex with specified attributes.</dd>
<dt id="pthread_mutex_lock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_lock"><code class="Fn">pthread_mutex_lock</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>)</dt>
<dd>Lock a mutex and block until it becomes available.</dd>
<dt id="pthread_mutex_timedlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_timedlock"><code class="Fn">pthread_mutex_timedlock</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>, <var class="Fa">const struct timespec *abstime</var>);</dt>
<dd>Lock a mutex and block until it becomes available or until the timeout
expires.</dd>
<dt id="pthread_mutex_trylock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_trylock"><code class="Fn">pthread_mutex_trylock</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>)</dt>
<dd>Try to lock a mutex, but do not block if the mutex is locked by another
thread, including the current thread.</dd>
<dt id="pthread_mutex_unlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_mutex_unlock"><code class="Fn">pthread_mutex_unlock</code></a>(<var class="Fa">pthread_mutex_t
*mutex</var>)</dt>
<dd>Unlock a mutex.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Condition_Variable_Routines"><a class="permalink" href="#Condition_Variable_Routines">Condition
Variable Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_condattr_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_condattr_destroy"><code class="Fn">pthread_condattr_destroy</code></a>(<var class="Fa">pthread_condattr_t
*attr</var>)</dt>
<dd>Destroy a condition variable attributes object.</dd>
<dt id="pthread_condattr_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_condattr_init"><code class="Fn">pthread_condattr_init</code></a>(<var class="Fa">pthread_condattr_t
*attr</var>)</dt>
<dd>Initialize a condition variable attributes object with default
values.</dd>
<dt id="pthread_cond_broadcast"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_broadcast"><code class="Fn">pthread_cond_broadcast</code></a>(<var class="Fa">pthread_cond_t
*cond</var>)</dt>
<dd>Unblock all threads currently blocked on the specified condition
variable.</dd>
<dt id="pthread_cond_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_destroy"><code class="Fn">pthread_cond_destroy</code></a>(<var class="Fa">pthread_cond_t
*cond</var>)</dt>
<dd>Destroy a condition variable.</dd>
<dt id="pthread_cond_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_init"><code class="Fn">pthread_cond_init</code></a>(<var class="Fa">pthread_cond_t
*cond</var>, <var class="Fa">const pthread_condattr_t *attr</var>)</dt>
<dd>Initialize a condition variable with specified attributes.</dd>
<dt id="pthread_cond_signal"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_signal"><code class="Fn">pthread_cond_signal</code></a>(<var class="Fa">pthread_cond_t
*cond</var>)</dt>
<dd>Unblock at least one of the threads blocked on the specified condition
variable.</dd>
<dt id="pthread_cond_timedwait"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_timedwait"><code class="Fn">pthread_cond_timedwait</code></a>(<var class="Fa">pthread_cond_t
*cond</var>, <var class="Fa">pthread_mutex_t *mutex</var>,
<var class="Fa">const struct timespec *abstime</var>);</dt>
<dd>Unlock the specified mutex, wait no longer than the specified time for a
condition, and then relock the mutex.</dd>
<dt id="pthread_cond_wait"><var class="Ft">int</var>
<a class="permalink" href="#pthread_cond_wait"><code class="Fn">pthread_cond_wait</code></a>(<var class="Fa">pthread_cond_t
*</var>, <var class="Fa">pthread_mutex_t *mutex</var>)</dt>
<dd>Unlock the specified mutex, wait for a condition, and relock the
mutex.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Read/Write_Lock_Routines"><a class="permalink" href="#Read/Write_Lock_Routines">Read/Write
Lock Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_rwlock_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_destroy"><code class="Fn">pthread_rwlock_destroy</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Destroy a read/write lock object.</dd>
<dt id="pthread_rwlock_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_init"><code class="Fn">pthread_rwlock_init</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>, <var class="Fa">const pthread_rwlockattr_t *attr</var>);</dt>
<dd>Initialize a read/write lock object.</dd>
<dt id="pthread_rwlock_rdlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_rdlock"><code class="Fn">pthread_rwlock_rdlock</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Lock a read/write lock for reading, blocking until the lock can be
acquired.</dd>
<dt id="pthread_rwlock_tryrdlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_tryrdlock"><code class="Fn">pthread_rwlock_tryrdlock</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Attempt to lock a read/write lock for reading, without blocking if the
lock is unavailable.</dd>
<dt id="pthread_rwlock_trywrlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_trywrlock"><code class="Fn">pthread_rwlock_trywrlock</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Attempt to lock a read/write lock for writing, without blocking if the
lock is unavailable.</dd>
<dt id="pthread_rwlock_unlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_unlock"><code class="Fn">pthread_rwlock_unlock</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Unlock a read/write lock.</dd>
<dt id="pthread_rwlock_wrlock"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlock_wrlock"><code class="Fn">pthread_rwlock_wrlock</code></a>(<var class="Fa">pthread_rwlock_t
*lock</var>)</dt>
<dd>Lock a read/write lock for writing, blocking until the lock can be
acquired.</dd>
<dt id="pthread_rwlockattr_destroy"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlockattr_destroy"><code class="Fn">pthread_rwlockattr_destroy</code></a>(<var class="Fa">pthread_rwlockattr_t
*attr</var>)</dt>
<dd>Destroy a read/write lock attribute object.</dd>
<dt id="pthread_rwlockattr_getpshared"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlockattr_getpshared"><code class="Fn">pthread_rwlockattr_getpshared</code></a>(<var class="Fa">const
pthread_rwlockattr_t *attr</var>, <var class="Fa">int *pshared</var>);</dt>
<dd>Retrieve the process shared setting for the read/write lock attribute
object.</dd>
<dt id="pthread_rwlockattr_init"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlockattr_init"><code class="Fn">pthread_rwlockattr_init</code></a>(<var class="Fa">pthread_rwlockattr_t
*attr</var>)</dt>
<dd>Initialize a read/write lock attribute object.</dd>
<dt id="pthread_rwlockattr_setpshared"><var class="Ft">int</var>
<a class="permalink" href="#pthread_rwlockattr_setpshared"><code class="Fn">pthread_rwlockattr_setpshared</code></a>(<var class="Fa">pthread_rwlockattr_t
*attr</var>, <var class="Fa">int pshared</var>)</dt>
<dd>Set the process shared setting for the read/write lock attribute
object.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Per-Thread_Context_Routines"><a class="permalink" href="#Per-Thread_Context_Routines">Per-Thread
Context Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_key_create"><var class="Ft">int</var>
<a class="permalink" href="#pthread_key_create"><code class="Fn">pthread_key_create</code></a>(<var class="Fa">pthread_key_t
*key</var>, <var class="Fa">void (*routine)(void *)</var>)</dt>
<dd>Create a thread-specific data key.</dd>
<dt id="pthread_key_delete"><var class="Ft">int</var>
<a class="permalink" href="#pthread_key_delete"><code class="Fn">pthread_key_delete</code></a>(<var class="Fa">pthread_key_t
key</var>)</dt>
<dd>Delete a thread-specific data key.</dd>
<dt id="pthread_getspecific"><var class="Ft">void *</var>
<a class="permalink" href="#pthread_getspecific"><code class="Fn">pthread_getspecific</code></a>(<var class="Fa">pthread_key_t
key</var>)</dt>
<dd>Get the thread-specific value for the specified key.</dd>
<dt id="pthread_setspecific"><var class="Ft">int</var>
<a class="permalink" href="#pthread_setspecific"><code class="Fn">pthread_setspecific</code></a>(<var class="Fa">pthread_key_t
key</var>, <var class="Fa">const void *value_ptr</var>)</dt>
<dd>Set the thread-specific value for the specified key.</dd>
</dl>
</section>
<section class="Ss">
<h2 class="Ss" id="Cleanup_Routines"><a class="permalink" href="#Cleanup_Routines">Cleanup
Routines</a></h2>
<dl class="Bl-tag">
<dt id="pthread_atfork"><var class="Ft">int</var>
<a class="permalink" href="#pthread_atfork"><code class="Fn">pthread_atfork</code></a>(<var class="Fa">void
(*prepare)(void)</var>, <var class="Fa">void (*parent)(void)</var>,
<var class="Fa">void (*child)(void)</var>);</dt>
<dd>Register fork handlers.</dd>
<dt id="pthread_cleanup_pop"><var class="Ft">void</var>
<a class="permalink" href="#pthread_cleanup_pop"><code class="Fn">pthread_cleanup_pop</code></a>(<var class="Fa">int
execute</var>)</dt>
<dd>Remove the routine at the top of the calling thread's cancellation cleanup
stack and optionally invoke it.</dd>
<dt id="pthread_cleanup_push"><var class="Ft">void</var>
<a class="permalink" href="#pthread_cleanup_push"><code class="Fn">pthread_cleanup_push</code></a>(<var class="Fa">void
(*routine)(void *)</var>, <var class="Fa">void *routine_arg</var>)</dt>
<dd>Push the specified cancellation cleanup handler onto the calling thread's
cancellation stack.</dd>
</dl>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="IMPLEMENTATION_NOTES"><a class="permalink" href="#IMPLEMENTATION_NOTES">IMPLEMENTATION
NOTES</a></h1>
<p class="Pp">The current <span class="Ux">FreeBSD</span> POSIX thread
implementation is built into the <span class="Lb">1:1 Threading Library
(libthr, -lthr)</span> library. It contains thread-safe versions of
<span class="Lb">Standard C Library (libc, -lc)</span> functions and
the thread functions. Threaded applications are linked with this
library.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">libthr(3)</a>, <a class="Xr">pthread_atfork(3)</a>,
<a class="Xr">pthread_attr(3)</a>, <a class="Xr">pthread_cancel(3)</a>,
<a class="Xr">pthread_cleanup_pop(3)</a>,
<a class="Xr">pthread_cleanup_push(3)</a>,
<a class="Xr">pthread_cond_broadcast(3)</a>,
<a class="Xr">pthread_cond_destroy(3)</a>,
<a class="Xr">pthread_cond_init(3)</a>,
<a class="Xr">pthread_cond_signal(3)</a>,
<a class="Xr">pthread_cond_timedwait(3)</a>,
<a class="Xr">pthread_cond_wait(3)</a>,
<a class="Xr">pthread_condattr_destroy(3)</a>,
<a class="Xr">pthread_condattr_init(3)</a>,
<a class="Xr">pthread_create(3)</a>, <a class="Xr">pthread_detach(3)</a>,
<a class="Xr">pthread_equal(3)</a>, <a class="Xr">pthread_exit(3)</a>,
<a class="Xr">pthread_getspecific(3)</a>, <a class="Xr">pthread_join(3)</a>,
<a class="Xr">pthread_key_delete(3)</a>, <a class="Xr">pthread_kill(3)</a>,
<a class="Xr">pthread_mutex_destroy(3)</a>,
<a class="Xr">pthread_mutex_init(3)</a>,
<a class="Xr">pthread_mutex_lock(3)</a>,
<a class="Xr">pthread_mutex_trylock(3)</a>,
<a class="Xr">pthread_mutex_unlock(3)</a>,
<a class="Xr">pthread_mutexattr_destroy(3)</a>,
<a class="Xr">pthread_mutexattr_getprioceiling(3)</a>,
<a class="Xr">pthread_mutexattr_getprotocol(3)</a>,
<a class="Xr">pthread_mutexattr_gettype(3)</a>,
<a class="Xr">pthread_mutexattr_init(3)</a>,
<a class="Xr">pthread_mutexattr_setprioceiling(3)</a>,
<a class="Xr">pthread_mutexattr_setprotocol(3)</a>,
<a class="Xr">pthread_mutexattr_settype(3)</a>,
<a class="Xr">pthread_np(3)</a>, <a class="Xr">pthread_once(3)</a>,
<a class="Xr">pthread_rwlock_destroy(3)</a>,
<a class="Xr">pthread_rwlock_init(3)</a>,
<a class="Xr">pthread_rwlock_rdlock(3)</a>,
<a class="Xr">pthread_rwlock_unlock(3)</a>,
<a class="Xr">pthread_rwlock_wrlock(3)</a>,
<a class="Xr">pthread_rwlockattr_destroy(3)</a>,
<a class="Xr">pthread_rwlockattr_getpshared(3)</a>,
<a class="Xr">pthread_rwlockattr_init(3)</a>,
<a class="Xr">pthread_rwlockattr_setpshared(3)</a>,
<a class="Xr">pthread_self(3)</a>,
<a class="Xr">pthread_setcancelstate(3)</a>,
<a class="Xr">pthread_setcanceltype(3)</a>,
<a class="Xr">pthread_setspecific(3)</a>,
<a class="Xr">pthread_testcancel(3)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="STANDARDS"><a class="permalink" href="#STANDARDS">STANDARDS</a></h1>
<p class="Pp">The functions with the <code class="Nm">pthread_</code> prefix and
not <code class="Nm">_np</code> suffix or
<code class="Nm">pthread_rwlock</code> prefix conform to
<span class="St">ISO/IEC 9945-1:1996 (“POSIX.1”)</span>.</p>
<p class="Pp">The functions with the <code class="Nm">pthread_</code> prefix and
<code class="Nm">_np</code> suffix are non-portable extensions to POSIX
threads.</p>
<p class="Pp">The functions with the <code class="Nm">pthread_rwlock</code>
prefix are extensions created by The Open Group as part of the
<span class="St">Version 2 of the Single UNIX Specification
(“SUSv2”)</span>.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">October 12, 2021</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|