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
12 pthread.h — threads
13
15 #include <pthread.h>
16
18 The <pthread.h> header shall define the following symbolic constants:
19
20 PTHREAD_BARRIER_SERIAL_THREAD
21 PTHREAD_CANCEL_ASYNCHRONOUS
22 PTHREAD_CANCEL_ENABLE
23 PTHREAD_CANCEL_DEFERRED
24 PTHREAD_CANCEL_DISABLE
25 PTHREAD_CANCELED
26 PTHREAD_CREATE_DETACHED
27 PTHREAD_CREATE_JOINABLE
28 PTHREAD_EXPLICIT_SCHED
29 PTHREAD_INHERIT_SCHED
30 PTHREAD_MUTEX_DEFAULT
31 PTHREAD_MUTEX_ERRORCHECK
32 PTHREAD_MUTEX_NORMAL
33 PTHREAD_MUTEX_RECURSIVE
34 PTHREAD_MUTEX_ROBUST
35 PTHREAD_MUTEX_STALLED
36 PTHREAD_ONCE_INIT
37 PTHREAD_PRIO_INHERIT
38 PTHREAD_PRIO_NONE
39 PTHREAD_PRIO_PROTECT
40 PTHREAD_PROCESS_SHARED
41 PTHREAD_PROCESS_PRIVATE
42 PTHREAD_SCOPE_PROCESS
43 PTHREAD_SCOPE_SYSTEM
44
45 The <pthread.h> header shall define the following compile-time constant
46 expressions valid as initializers for the following types:
47
48 ┌───────────────────────────┬──────────────────────┐
49 │ Name │ Initializer for Type │
50 ├───────────────────────────┼──────────────────────┤
51 │PTHREAD_COND_INITIALIZER │ pthread_cond_t │
52 │PTHREAD_MUTEX_INITIALIZER │ pthread_mutex_t │
53 │PTHREAD_RWLOCK_INITIALIZER │ pthread_rwlock_t │
54 └───────────────────────────┴──────────────────────┘
55 The <pthread.h> header shall define the pthread_attr_t, pthread_bar‐
56 rier_t, pthread_barrierattr_t, pthread_cond_t, pthread_condattr_t,
57 pthread_key_t, pthread_mutex_t, pthread_mutexattr_t, pthread_once_t,
58 pthread_rwlock_t, pthread_rwlockattr_t, pthread_spinlock_t, and
59 pthread_t types as described in <sys/types.h>.
60
61 The following shall be declared as functions and may also be defined as
62 macros. Function prototypes shall be provided.
63
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 int pthread_cond_broadcast(pthread_cond_t *);
104 int pthread_cond_destroy(pthread_cond_t *);
105 int pthread_cond_init(pthread_cond_t *restrict,
106 const pthread_condattr_t *restrict);
107 int pthread_cond_signal(pthread_cond_t *);
108 int pthread_cond_timedwait(pthread_cond_t *restrict,
109 pthread_mutex_t *restrict, const struct timespec *restrict);
110 int pthread_cond_wait(pthread_cond_t *restrict,
111 pthread_mutex_t *restrict);
112 int pthread_condattr_destroy(pthread_condattr_t *);
113 int pthread_condattr_getclock(const pthread_condattr_t *restrict,
114 clockid_t *restrict);
115 int pthread_condattr_getpshared(const pthread_condattr_t *restrict,
116 int *restrict);
117 int pthread_condattr_init(pthread_condattr_t *);
118 int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
119 int pthread_condattr_setpshared(pthread_condattr_t *, int);
120 int pthread_create(pthread_t *restrict, const pthread_attr_t *restrict,
121 void *(*)(void*), void *restrict);
122 int pthread_detach(pthread_t);
123 int pthread_equal(pthread_t, pthread_t);
124 void pthread_exit(void *);
125 int pthread_getconcurrency(void);
126 int pthread_getcpuclockid(pthread_t, clockid_t *);
127 int pthread_getschedparam(pthread_t, int *restrict,
128 struct sched_param *restrict);
129 void *pthread_getspecific(pthread_key_t);
130 int pthread_join(pthread_t, void **);
131 int pthread_key_create(pthread_key_t *, void (*)(void*));
132 int pthread_key_delete(pthread_key_t);
133 int pthread_mutex_consistent(pthread_mutex_t *);
134 int pthread_mutex_destroy(pthread_mutex_t *);
135 int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict,
136 int *restrict);
137 int pthread_mutex_init(pthread_mutex_t *restrict,
138 const pthread_mutexattr_t *restrict);
139 int pthread_mutex_lock(pthread_mutex_t *);
140 int pthread_mutex_setprioceiling(pthread_mutex_t *restrict, int,
141 int *restrict);
142 int pthread_mutex_timedlock(pthread_mutex_t *restrict,
143 const struct timespec *restrict);
144 int pthread_mutex_trylock(pthread_mutex_t *);
145 int pthread_mutex_unlock(pthread_mutex_t *);
146 int pthread_mutexattr_destroy(pthread_mutexattr_t *);
147 int pthread_mutexattr_getprioceiling(
148 const pthread_mutexattr_t *restrict, int *restrict);
149 int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict,
150 int *restrict);
151 int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict,
152 int *restrict);
153 int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict,
154 int *restrict);
155 int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict,
156 int *restrict);
157 int pthread_mutexattr_init(pthread_mutexattr_t *);
158 int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
159 int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
160 int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
161 int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
162 int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
163 int pthread_once(pthread_once_t *, void (*)(void));
164 int pthread_rwlock_destroy(pthread_rwlock_t *);
165 int pthread_rwlock_init(pthread_rwlock_t *restrict,
166 const pthread_rwlockattr_t *restrict);
167 int pthread_rwlock_rdlock(pthread_rwlock_t *);
168 int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict,
169 const struct timespec *restrict);
170 int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict,
171 const struct timespec *restrict);
172 int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
173 int pthread_rwlock_trywrlock(pthread_rwlock_t *);
174 int pthread_rwlock_unlock(pthread_rwlock_t *);
175 int pthread_rwlock_wrlock(pthread_rwlock_t *);
176 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
177 int pthread_rwlockattr_getpshared(
178 const pthread_rwlockattr_t *restrict, int *restrict);
179 int pthread_rwlockattr_init(pthread_rwlockattr_t *);
180 int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
181 pthread_t
182 pthread_self(void);
183 int pthread_setcancelstate(int, int *);
184 int pthread_setcanceltype(int, int *);
185 int pthread_setconcurrency(int);
186 int pthread_setschedparam(pthread_t, int,
187 const struct sched_param *);
188 int pthread_setschedprio(pthread_t, int);
189 int pthread_setspecific(pthread_key_t, const void *);
190 int pthread_spin_destroy(pthread_spinlock_t *);
191 int pthread_spin_init(pthread_spinlock_t *, int);
192 int pthread_spin_lock(pthread_spinlock_t *);
193 int pthread_spin_trylock(pthread_spinlock_t *);
194 int pthread_spin_unlock(pthread_spinlock_t *);
195 void pthread_testcancel(void);
196
197 The following may be declared as functions, or defined as macros, or
198 both. If functions are declared, function prototypes shall be pro‐
199 vided.
200
201 pthread_cleanup_pop() pthread_cleanup_push()
202
203 Inclusion of the <pthread.h> header shall make symbols defined in the
204 headers <sched.h> and <time.h> visible.
205
206 The following sections are informative.
207
209 None.
210
212 None.
213
215 None.
216
218 <sched.h>, <sys_types.h>, <time.h>
219
220 The System Interfaces volume of POSIX.1‐2017, pthread_atfork(),
221 pthread_attr_destroy(), pthread_attr_getdetachstate(),
222 pthread_attr_getguardsize(), pthread_attr_getinheritsched(),
223 pthread_attr_getschedparam(), pthread_attr_getschedpolicy(),
224 pthread_attr_getscope(), pthread_attr_getstack(), pthread_attr_get‐
225 stacksize(), pthread_barrier_destroy(), pthread_barrier_wait(),
226 pthread_barrierattr_destroy(), pthread_barrierattr_getpshared(),
227 pthread_cancel(), pthread_cleanup_pop(), pthread_cond_broadcast(),
228 pthread_cond_destroy(), pthread_cond_timedwait(), pthread_con‐
229 dattr_destroy(), pthread_condattr_getclock(), pthread_condattr_getp‐
230 shared(), pthread_create(), pthread_detach(), pthread_equal(),
231 pthread_exit(), pthread_getconcurrency(), pthread_getcpuclockid(),
232 pthread_getschedparam(), pthread_getspecific(), pthread_join(),
233 pthread_key_create(), pthread_key_delete(), pthread_mutex_consistent(),
234 pthread_mutex_destroy(), pthread_mutex_getprioceiling(),
235 pthread_mutex_lock(), pthread_mutex_timedlock(), pthread_mutex‐
236 attr_destroy(), pthread_mutexattr_getprioceiling(), pthread_mutex‐
237 attr_getprotocol(), pthread_mutexattr_getpshared(), pthread_mutex‐
238 attr_getrobust(), pthread_mutexattr_gettype(), pthread_once(),
239 pthread_rwlock_destroy(), pthread_rwlock_rdlock(), pthread_rwlock_time‐
240 drdlock(), pthread_rwlock_timedwrlock(), pthread_rwlock_trywrlock(),
241 pthread_rwlock_unlock(), pthread_rwlockattr_destroy(), pthread_rwlock‐
242 attr_getpshared(), pthread_self(), pthread_setcancelstate(),
243 pthread_setschedprio(), pthread_spin_destroy(), pthread_spin_lock(),
244 pthread_spin_unlock()
245
247 Portions of this text are reprinted and reproduced in electronic form
248 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
249 table Operating System Interface (POSIX), The Open Group Base Specifi‐
250 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
251 Electrical and Electronics Engineers, Inc and The Open Group. In the
252 event of any discrepancy between this version and the original IEEE and
253 The Open Group Standard, the original IEEE and The Open Group Standard
254 is the referee document. The original Standard can be obtained online
255 at http://www.opengroup.org/unix/online.html .
256
257 Any typographical or formatting errors that appear in this page are
258 most likely to have been introduced during the conversion of the source
259 files to man page format. To report such errors, see https://www.ker‐
260 nel.org/doc/man-pages/reporting_bugs.html .
261
262
263
264IEEE/The Open Group 2017 pthread.h(0P)