1pthread.h(0P) POSIX Programmer's Manual pthread.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 pthread.h — threads
14
16 #include <pthread.h>
17
19 The <pthread.h> header shall define the following symbolic constants:
20
21 PTHREAD_BARRIER_SERIAL_THREAD
22 PTHREAD_CANCEL_ASYNCHRONOUS
23 PTHREAD_CANCEL_ENABLE
24 PTHREAD_CANCEL_DEFERRED
25 PTHREAD_CANCEL_DISABLE
26 PTHREAD_CANCELED
27 PTHREAD_CREATE_DETACHED
28 PTHREAD_CREATE_JOINABLE
29 PTHREAD_EXPLICIT_SCHED
30 PTHREAD_INHERIT_SCHED
31 PTHREAD_MUTEX_DEFAULT
32 PTHREAD_MUTEX_ERRORCHECK
33 PTHREAD_MUTEX_NORMAL
34 PTHREAD_MUTEX_RECURSIVE
35 PTHREAD_MUTEX_ROBUST
36 PTHREAD_MUTEX_STALLED
37 PTHREAD_ONCE_INIT
38 PTHREAD_PRIO_INHERIT
39 PTHREAD_PRIO_NONE
40 PTHREAD_PRIO_PROTECT
41 PTHREAD_PROCESS_SHARED
42 PTHREAD_PROCESS_PRIVATE
43 PTHREAD_SCOPE_PROCESS
44 PTHREAD_SCOPE_SYSTEM
45
46 The <pthread.h> header shall define the following compile-time constant
47 expressions valid as initializers for the following types:
48
49 ┌───────────────────────────┬──────────────────────┐
50 │ Name │ Initializer for Type │
51 ├───────────────────────────┼──────────────────────┤
52 │PTHREAD_COND_INITIALIZER │ pthread_cond_t │
53 │PTHREAD_MUTEX_INITIALIZER │ pthread_mutex_t │
54 │PTHREAD_RWLOCK_INITIALIZER │ pthread_rwlock_t │
55 └───────────────────────────┴──────────────────────┘
56 The <pthread.h> header shall define the pthread_attr_t, pthread_bar‐
57 rier_t, pthread_barrierattr_t, pthread_cond_t, pthread_condattr_t,
58 pthread_key_t, pthread_mutex_t, pthread_mutexattr_t, pthread_once_t,
59 pthread_rwlock_t, pthread_rwlockattr_t, pthread_spinlock_t, and
60 pthread_t types as described in <sys/types.h>.
61
62 The following shall be declared as functions and may also be defined as
63 macros. Function prototypes shall be provided.
64
65 int pthread_atfork(void (*)(void), void (*)(void),
66 void(*)(void));
67 int pthread_attr_destroy(pthread_attr_t *);
68 int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
69 int pthread_attr_getguardsize(const pthread_attr_t *restrict,
70 size_t *restrict);
71 int pthread_attr_getinheritsched(const pthread_attr_t *restrict,
72 int *restrict);
73 int pthread_attr_getschedparam(const pthread_attr_t *restrict,
74 struct sched_param *restrict);
75 int pthread_attr_getschedpolicy(const pthread_attr_t *restrict,
76 int *restrict);
77 int pthread_attr_getscope(const pthread_attr_t *restrict,
78 int *restrict);
79 int pthread_attr_getstack(const pthread_attr_t *restrict,
80 void **restrict, size_t *restrict);
81 int pthread_attr_getstacksize(const pthread_attr_t *restrict,
82 size_t *restrict);
83 int pthread_attr_init(pthread_attr_t *);
84 int pthread_attr_setdetachstate(pthread_attr_t *, int);
85 int pthread_attr_setguardsize(pthread_attr_t *, size_t);
86 int pthread_attr_setinheritsched(pthread_attr_t *, int);
87 int pthread_attr_setschedparam(pthread_attr_t *restrict,
88 const struct sched_param *restrict);
89 int pthread_attr_setschedpolicy(pthread_attr_t *, int);
90 int pthread_attr_setscope(pthread_attr_t *, int);
91 int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
92 int pthread_attr_setstacksize(pthread_attr_t *, size_t);
93 int pthread_barrier_destroy(pthread_barrier_t *);
94 int pthread_barrier_init(pthread_barrier_t *restrict,
95 const pthread_barrierattr_t *restrict, unsigned);
96 int pthread_barrier_wait(pthread_barrier_t *);
97 int pthread_barrierattr_destroy(pthread_barrierattr_t *);
98 int pthread_barrierattr_getpshared(
99 const pthread_barrierattr_t *restrict, int *restrict);
100 int pthread_barrierattr_init(pthread_barrierattr_t *);
101 int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
102 int pthread_cancel(pthread_t);
103 void pthread_cleanup_pop(int);
104 void pthread_cleanup_push(void (*)(void*), void *);
105 int pthread_cond_broadcast(pthread_cond_t *);
106 int pthread_cond_destroy(pthread_cond_t *);
107 int pthread_cond_init(pthread_cond_t *restrict,
108 const pthread_condattr_t *restrict);
109 int pthread_cond_signal(pthread_cond_t *);
110 int pthread_cond_timedwait(pthread_cond_t *restrict,
111 pthread_mutex_t *restrict, const struct timespec *restrict);
112 int pthread_cond_wait(pthread_cond_t *restrict,
113 pthread_mutex_t *restrict);
114 int pthread_condattr_destroy(pthread_condattr_t *);
115 int pthread_condattr_getclock(const pthread_condattr_t *restrict,
116 clockid_t *restrict);
117 int pthread_condattr_getpshared(const pthread_condattr_t *restrict,
118 int *restrict);
119 int pthread_condattr_init(pthread_condattr_t *);
120 int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
121 int pthread_condattr_setpshared(pthread_condattr_t *, int);
122 int pthread_create(pthread_t *restrict, const pthread_attr_t *restrict,
123 void *(*)(void*), void *restrict);
124 int pthread_detach(pthread_t);
125 int pthread_equal(pthread_t, pthread_t);
126 void pthread_exit(void *);
127 int pthread_getconcurrency(void);
128 int pthread_getcpuclockid(pthread_t, clockid_t *);
129 int pthread_getschedparam(pthread_t, int *restrict,
130 struct sched_param *restrict);
131 void *pthread_getspecific(pthread_key_t);
132 int pthread_join(pthread_t, void **);
133 int pthread_key_create(pthread_key_t *, void (*)(void*));
134 int pthread_key_delete(pthread_key_t);
135 int pthread_mutex_consistent(pthread_mutex_t *);
136 int pthread_mutex_destroy(pthread_mutex_t *);
137 int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict,
138 int *restrict);
139 int pthread_mutex_init(pthread_mutex_t *restrict,
140 const pthread_mutexattr_t *restrict);
141 int pthread_mutex_lock(pthread_mutex_t *);
142 int pthread_mutex_setprioceiling(pthread_mutex_t *restrict, int,
143 int *restrict);
144 int pthread_mutex_timedlock(pthread_mutex_t *restrict,
145 const struct timespec *restrict);
146 int pthread_mutex_trylock(pthread_mutex_t *);
147 int pthread_mutex_unlock(pthread_mutex_t *);
148 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
149 int pthread_mutexattr_getprioceiling(
150 const pthread_mutexattr_t *restrict, int *restrict);
151 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict,
152 int *restrict);
153 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict,
154 int *restrict);
155 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict,
156 int *restrict);
157 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict,
158 int *restrict);
159 int pthread_mutexattr_init(pthread_mutexattr_t *);
160 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
161 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
162 int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
163 int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
164 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
165 int pthread_once(pthread_once_t *, void (*)(void));
166 int pthread_rwlock_destroy(pthread_rwlock_t *);
167 int pthread_rwlock_init(pthread_rwlock_t *restrict,
168 const pthread_rwlockattr_t *restrict);
169 int pthread_rwlock_rdlock(pthread_rwlock_t *);
170 int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict,
171 const struct timespec *restrict);
172 int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict,
173 const struct timespec *restrict);
174 int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
175 int pthread_rwlock_trywrlock(pthread_rwlock_t *);
176 int pthread_rwlock_unlock(pthread_rwlock_t *);
177 int pthread_rwlock_wrlock(pthread_rwlock_t *);
178 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
179 int pthread_rwlockattr_getpshared(
180 const pthread_rwlockattr_t *restrict, int *restrict);
181 int pthread_rwlockattr_init(pthread_rwlockattr_t *);
182 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
183 pthread_t
184 pthread_self(void);
185 int pthread_setcancelstate(int, int *);
186 int pthread_setcanceltype(int, int *);
187 int pthread_setconcurrency(int);
188 int pthread_setschedparam(pthread_t, int,
189 const struct sched_param *);
190 int pthread_setschedprio(pthread_t, int);
191 int pthread_setspecific(pthread_key_t, const void *);
192 int pthread_spin_destroy(pthread_spinlock_t *);
193 int pthread_spin_init(pthread_spinlock_t *, int);
194 int pthread_spin_lock(pthread_spinlock_t *);
195 int pthread_spin_trylock(pthread_spinlock_t *);
196 int pthread_spin_unlock(pthread_spinlock_t *);
197 void pthread_testcancel(void);
198
199 Inclusion of the <pthread.h> header shall make symbols defined in the
200 headers <sched.h> and <time.h> visible.
201
202 The following sections are informative.
203
205 None.
206
208 None.
209
211 None.
212
214 <sched.h>, <sys_types.h>, <time.h>
215
216 The System Interfaces volume of POSIX.1‐2008, pthread_atfork(),
217 pthread_attr_destroy(), pthread_attr_getdetachstate(),
218 pthread_attr_getguardsize(), pthread_attr_getinheritsched(),
219 pthread_attr_getschedparam(), pthread_attr_getschedpolicy(),
220 pthread_attr_getscope(), pthread_attr_getstack(), pthread_attr_get‐
221 stacksize(), pthread_barrier_destroy(), pthread_barrier_wait(),
222 pthread_barrierattr_destroy(), pthread_barrierattr_getpshared(),
223 pthread_cancel(), pthread_cleanup_pop(), pthread_cond_broadcast(),
224 pthread_cond_destroy(), pthread_cond_timedwait(), pthread_con‐
225 dattr_destroy(), pthread_condattr_getclock(), pthread_condattr_getp‐
226 shared(), pthread_create(), pthread_detach(), pthread_equal(),
227 pthread_exit(), pthread_getconcurrency(), pthread_getcpuclockid(),
228 pthread_getschedparam(), pthread_getspecific(), pthread_join(),
229 pthread_key_create(), pthread_key_delete(), pthread_mutex_consistent(),
230 pthread_mutex_destroy(), pthread_mutex_getprioceiling(),
231 pthread_mutex_lock(), pthread_mutex_timedlock(), pthread_mutex‐
232 attr_destroy(), pthread_mutexattr_getprioceiling(), pthread_mutex‐
233 attr_getprotocol(), pthread_mutexattr_getpshared(), pthread_mutex‐
234 attr_getrobust(), pthread_mutexattr_gettype(), pthread_once(),
235 pthread_rwlock_destroy(), pthread_rwlock_rdlock(), pthread_rwlock_time‐
236 drdlock(), pthread_rwlock_timedwrlock(), pthread_rwlock_trywrlock(),
237 pthread_rwlock_unlock(), pthread_rwlockattr_destroy(), pthread_rwlock‐
238 attr_getpshared(), pthread_self(), pthread_setcancelstate(),
239 pthread_setschedprio(), pthread_spin_destroy(), pthread_spin_lock(),
240 pthread_spin_unlock()
241
243 Portions of this text are reprinted and reproduced in electronic form
244 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
245 -- Portable Operating System Interface (POSIX), The Open Group Base
246 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
247 cal and Electronics Engineers, Inc and The Open Group. (This is
248 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
249 event of any discrepancy between this version and the original IEEE and
250 The Open Group Standard, the original IEEE and The Open Group Standard
251 is the referee document. The original Standard can be obtained online
252 at http://www.unix.org/online.html .
253
254 Any typographical or formatting errors that appear in this page are
255 most likely to have been introduced during the conversion of the source
256 files to man page format. To report such errors, see https://www.ker‐
257 nel.org/doc/man-pages/reporting_bugs.html .
258
259
260
261IEEE/The Open Group 2013 pthread.h(0P)