CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Mon, 28 Jul 2025 00:22:18 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20170228185108
location: https://web.archive.org/web/20170228185108/https://perl5.git.perl.org/perl.git/blob/HEAD:/thread.h
server-timing: captures_list;dur=0.728842, exclusion.robots;dur=0.035624, exclusion.robots.policy;dur=0.021956, esindex;dur=0.013286, cdx.remote;dur=134.755250, LoadShardBlock;dur=79.336562, PetaboxLoader3.datanode;dur=69.936357
x-app-server: wwwb-app202
x-ts: 302
x-tr: 244
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: SERVER=wwwb-app202; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Mon, 28 Jul 2025 00:22:19 GMT
content-type: application/xhtml+xml; charset=utf-8
x-archive-orig-date: Tue, 28 Feb 2017 18:51:07 GMT
x-archive-orig-server: Apache/2.2.15 (CentOS)
x-archive-orig-connection: close
x-archive-orig-transfer-encoding: chunked
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Tue, 28 Feb 2017 18:51:08 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 28 Feb 2017 18:51:06 GMT", ; rel="prev memento"; datetime="Tue, 28 Feb 2017 18:51:06 GMT", ; rel="memento"; datetime="Tue, 28 Feb 2017 18:51:08 GMT", ; rel="last memento"; datetime="Tue, 28 Feb 2017 18:51:08 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: falconk_archivebot_www_perlmonks_org_20170214/www.perlmonks.org-inf-20170214-150724-7wgmd-00008.warc.gz
server-timing: captures_list;dur=0.457486, exclusion.robots;dur=0.021104, exclusion.robots.policy;dur=0.012938, esindex;dur=0.009619, cdx.remote;dur=348.658691, LoadShardBlock;dur=234.451280, PetaboxLoader3.datanode;dur=69.317479, load_resource;dur=95.292932, PetaboxLoader3.resolve;dur=75.468113
x-app-server: wwwb-app202
x-ts: 200
x-tr: 836
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
Perl 5 - perl.git/blob - thread.h
1 /* thread.h
2 *
3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 * by Larry Wall and others
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 */
11 #if defined(USE_ITHREADS)
13 #if defined(VMS)
14 #include <builtins.h>
15 #endif
17 #ifdef WIN32
18 # include <win32thread.h>
19 #else
20 #ifdef NETWARE
21 # include <nw5thread.h>
22 #else
23 # ifdef OLD_PTHREADS_API /* Here be dragons. */
24 # define DETACH(t) \
25 STMT_START { \
26 int _eC_; \
27 if ((_eC_ = pthread_detach(&(t)->self))) { \
28 MUTEX_UNLOCK(&(t)->mutex); \
29 Perl_croak_nocontext("panic: DETACH (%d) [%s:%d]", \
30 _eC_, __FILE__, __LINE__); \
31 } \
32 } STMT_END
34 # define PERL_GET_CONTEXT Perl_get_context()
35 # define PERL_SET_CONTEXT(t) Perl_set_context((void*)t)
37 # define PTHREAD_GETSPECIFIC_INT
38 # ifdef DJGPP
39 # define pthread_addr_t any_t
40 # define NEED_PTHREAD_INIT
41 # define PTHREAD_CREATE_JOINABLE (1)
42 # endif
43 # ifdef OEMVS
44 # define pthread_addr_t void *
45 # define pthread_create(t,a,s,d) pthread_create(t,&(a),s,d)
46 # define pthread_keycreate pthread_key_create
47 # endif
48 # ifdef VMS
49 # define pthread_attr_init(a) pthread_attr_create(a)
50 # define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_setdetach_np(a,s)
51 # define PTHREAD_CREATE(t,a,s,d) pthread_create(t,a,s,d)
52 # define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
53 # define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
54 # define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
55 # endif
56 # if defined(__hpux) && defined(__ux_version) && __ux_version <= 1020
57 # define pthread_attr_init(a) pthread_attr_create(a)
58 /* XXX pthread_setdetach_np() missing in DCE threads on HP-UX 10.20 */
59 # define PTHREAD_ATTR_SETDETACHSTATE(a,s) (0)
60 # define PTHREAD_CREATE(t,a,s,d) pthread_create(t,a,s,d)
61 # define pthread_key_create(k,d) pthread_keycreate(k,(pthread_destructor_t)(d))
62 # define pthread_mutexattr_init(a) pthread_mutexattr_create(a)
63 # define pthread_mutexattr_settype(a,t) pthread_mutexattr_setkind_np(a,t)
64 # endif
65 # if defined(DJGPP) || defined(OEMVS)
66 # define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,&(s))
67 # define YIELD pthread_yield(NULL)
68 # endif
69 # endif
70 # if !defined(__hpux) || !defined(__ux_version) || __ux_version > 1020
71 # define pthread_mutexattr_default NULL
72 # define pthread_condattr_default NULL
73 # endif
74 #endif /* NETWARE */
75 #endif
77 #ifndef PTHREAD_CREATE
78 /* You are not supposed to pass NULL as the 2nd arg of PTHREAD_CREATE(). */
79 # define PTHREAD_CREATE(t,a,s,d) pthread_create(t,&(a),s,d)
80 #endif
82 #ifndef PTHREAD_ATTR_SETDETACHSTATE
83 # define PTHREAD_ATTR_SETDETACHSTATE(a,s) pthread_attr_setdetachstate(a,s)
84 #endif
86 #ifndef PTHREAD_CREATE_JOINABLE
87 # ifdef OLD_PTHREAD_CREATE_JOINABLE
88 # define PTHREAD_CREATE_JOINABLE OLD_PTHREAD_CREATE_JOINABLE
89 # else
90 # define PTHREAD_CREATE_JOINABLE 0 /* Panic? No, guess. */
91 # endif
92 #endif
94 #ifdef __VMS
95 /* Default is 1024 on VAX, 8192 otherwise */
96 # ifdef __ia64
97 # define THREAD_CREATE_NEEDS_STACK (48*1024)
98 # else
99 # define THREAD_CREATE_NEEDS_STACK (32*1024)
100 # endif
101 #endif
103 #ifdef I_MACH_CTHREADS
105 /* cthreads interface */
107 /* #include <mach/cthreads.h> is in perl.h #ifdef I_MACH_CTHREADS */
109 #define MUTEX_INIT(m) \
110 STMT_START { \
111 *m = mutex_alloc(); \
112 if (*m) { \
113 mutex_init(*m); \
114 } else { \
115 Perl_croak_nocontext("panic: MUTEX_INIT [%s:%d]", \
116 __FILE__, __LINE__); \
117 } \
118 } STMT_END
120 #define MUTEX_LOCK(m) mutex_lock(*m)
121 #define MUTEX_UNLOCK(m) mutex_unlock(*m)
122 #define MUTEX_DESTROY(m) \
123 STMT_START { \
124 mutex_free(*m); \
125 *m = 0; \
126 } STMT_END
128 #define COND_INIT(c) \
129 STMT_START { \
130 *c = condition_alloc(); \
131 if (*c) { \
132 condition_init(*c); \
133 } \
134 else { \
135 Perl_croak_nocontext("panic: COND_INIT [%s:%d]", \
136 __FILE__, __LINE__); \
137 } \
138 } STMT_END
140 #define COND_SIGNAL(c) condition_signal(*c)
141 #define COND_BROADCAST(c) condition_broadcast(*c)
142 #define COND_WAIT(c, m) condition_wait(*c, *m)
143 #define COND_DESTROY(c) \
144 STMT_START { \
145 condition_free(*c); \
146 *c = 0; \
147 } STMT_END
149 #define THREAD_CREATE(thr, f) (thr->self = cthread_fork(f, thr), 0)
150 #define THREAD_POST_CREATE(thr)
152 #define THREAD_RET_TYPE any_t
153 #define THREAD_RET_CAST(x) ((any_t) x)
155 #define DETACH(t) cthread_detach(t->self)
156 #define JOIN(t, avp) (*(avp) = MUTABLE_AV(cthread_join(t->self)))
158 #define PERL_SET_CONTEXT(t) cthread_set_data(cthread_self(), t)
159 #define PERL_GET_CONTEXT cthread_data(cthread_self())
161 #define INIT_THREADS cthread_init()
162 #define YIELD cthread_yield()
163 #define ALLOC_THREAD_KEY NOOP
164 #define FREE_THREAD_KEY NOOP
165 #define SET_THREAD_SELF(thr) (thr->self = cthread_self())
167 #endif /* I_MACH_CTHREADS */
169 #ifndef YIELD
170 # ifdef SCHED_YIELD
171 # define YIELD SCHED_YIELD
172 # else
173 # ifdef HAS_SCHED_YIELD
174 # define YIELD sched_yield()
175 # else
176 # ifdef HAS_PTHREAD_YIELD
177 /* pthread_yield(NULL) platforms are expected
178 * to have #defined YIELD for themselves. */
179 # define YIELD pthread_yield()
180 # endif
181 # endif
182 # endif
183 #endif
185 #ifdef __hpux
186 # define MUTEX_INIT_NEEDS_MUTEX_ZEROED
187 #endif
189 #ifndef MUTEX_INIT
191 # ifdef MUTEX_INIT_NEEDS_MUTEX_ZEROED
192 /* Temporary workaround, true bug is deeper. --jhi 1999-02-25 */
193 # define MUTEX_INIT(m) \
194 STMT_START { \
195 int _eC_; \
196 Zero((m), 1, perl_mutex); \
197 if ((_eC_ = pthread_mutex_init((m), pthread_mutexattr_default))) \
198 Perl_croak_nocontext("panic: MUTEX_INIT (%d) [%s:%d]", \
199 _eC_, __FILE__, __LINE__); \
200 } STMT_END
201 # else
202 # define MUTEX_INIT(m) \
203 STMT_START { \
204 int _eC_; \
205 if ((_eC_ = pthread_mutex_init((m), pthread_mutexattr_default))) \
206 Perl_croak_nocontext("panic: MUTEX_INIT (%d) [%s:%d]", \
207 _eC_, __FILE__, __LINE__); \
208 } STMT_END
209 # endif
211 # ifdef PERL_TSA_ACTIVE
212 # define perl_pthread_mutex_lock(m) perl_tsa_mutex_lock(m)
213 # define perl_pthread_mutex_unlock(m) perl_tsa_mutex_unlock(m)
214 # else
215 # define perl_pthread_mutex_lock(m) pthread_mutex_lock(m)
216 # define perl_pthread_mutex_unlock(m) pthread_mutex_unlock(m)
217 # endif
219 # define MUTEX_LOCK(m) \
220 STMT_START { \
221 int _eC_; \
222 if ((_eC_ = perl_pthread_mutex_lock((m)))) \
223 Perl_croak_nocontext("panic: MUTEX_LOCK (%d) [%s:%d]", \
224 _eC_, __FILE__, __LINE__); \
225 } STMT_END
227 # define MUTEX_UNLOCK(m) \
228 STMT_START { \
229 int _eC_; \
230 if ((_eC_ = perl_pthread_mutex_unlock((m)))) \
231 Perl_croak_nocontext("panic: MUTEX_UNLOCK (%d) [%s:%d]", \
232 _eC_, __FILE__, __LINE__); \
233 } STMT_END
235 # define MUTEX_DESTROY(m) \
236 STMT_START { \
237 int _eC_; \
238 if ((_eC_ = pthread_mutex_destroy((m)))) \
239 Perl_croak_nocontext("panic: MUTEX_DESTROY (%d) [%s:%d]", \
240 _eC_, __FILE__, __LINE__); \
241 } STMT_END
242 #endif /* MUTEX_INIT */
244 #ifndef COND_INIT
245 # define COND_INIT(c) \
246 STMT_START { \
247 int _eC_; \
248 if ((_eC_ = pthread_cond_init((c), pthread_condattr_default))) \
249 Perl_croak_nocontext("panic: COND_INIT (%d) [%s:%d]", \
250 _eC_, __FILE__, __LINE__); \
251 } STMT_END
253 # define COND_SIGNAL(c) \
254 STMT_START { \
255 int _eC_; \
256 if ((_eC_ = pthread_cond_signal((c)))) \
257 Perl_croak_nocontext("panic: COND_SIGNAL (%d) [%s:%d]", \
258 _eC_, __FILE__, __LINE__); \
259 } STMT_END
261 # define COND_BROADCAST(c) \
262 STMT_START { \
263 int _eC_; \
264 if ((_eC_ = pthread_cond_broadcast((c)))) \
265 Perl_croak_nocontext("panic: COND_BROADCAST (%d) [%s:%d]", \
266 _eC_, __FILE__, __LINE__); \
267 } STMT_END
269 # define COND_WAIT(c, m) \
270 STMT_START { \
271 int _eC_; \
272 if ((_eC_ = pthread_cond_wait((c), (m)))) \
273 Perl_croak_nocontext("panic: COND_WAIT (%d) [%s:%d]", \
274 _eC_, __FILE__, __LINE__); \
275 } STMT_END
277 # define COND_DESTROY(c) \
278 STMT_START { \
279 int _eC_; \
280 if ((_eC_ = pthread_cond_destroy((c)))) \
281 Perl_croak_nocontext("panic: COND_DESTROY (%d) [%s:%d]", \
282 _eC_, __FILE__, __LINE__); \
283 } STMT_END
284 #endif /* COND_INIT */
286 /* DETACH(t) must only be called while holding t->mutex */
287 #ifndef DETACH
288 # define DETACH(t) \
289 STMT_START { \
290 int _eC_; \
291 if ((_eC_ = pthread_detach((t)->self))) { \
292 MUTEX_UNLOCK(&(t)->mutex); \
293 Perl_croak_nocontext("panic: DETACH (%d) [%s:%d]", \
294 _eC_, __FILE__, __LINE__); \
295 } \
296 } STMT_END
297 #endif /* DETACH */
299 #ifndef JOIN
300 # define JOIN(t, avp) \
301 STMT_START { \
302 int _eC_; \
303 if ((_eC_ = pthread_join((t)->self, (void**)(avp)))) \
304 Perl_croak_nocontext("panic: pthread_join (%d) [%s:%d]", \
305 _eC_, __FILE__, __LINE__); \
306 } STMT_END
307 #endif /* JOIN */
309 /* Use an unchecked fetch of thread-specific data instead of a checked one.
310 * It would fail if the key were bogus, but if the key were bogus then
311 * Really Bad Things would be happening anyway. --dan */
312 #if (defined(__ALPHA) && (__VMS_VER >= 70000000)) || \
313 (defined(__alpha) && defined(__osf__) && !defined(__GNUC__)) /* Available only on >= 4.0 */
314 # define HAS_PTHREAD_UNCHECKED_GETSPECIFIC_NP /* Configure test needed */
315 #endif
317 #ifdef HAS_PTHREAD_UNCHECKED_GETSPECIFIC_NP
318 # define PTHREAD_GETSPECIFIC(key) pthread_unchecked_getspecific_np(key)
319 #else
320 # define PTHREAD_GETSPECIFIC(key) pthread_getspecific(key)
321 #endif
323 #ifndef PERL_GET_CONTEXT
324 # define PERL_GET_CONTEXT PTHREAD_GETSPECIFIC(PL_thr_key)
325 #endif
327 #ifndef PERL_SET_CONTEXT
328 # define PERL_SET_CONTEXT(t) \
329 STMT_START { \
330 int _eC_; \
331 if ((_eC_ = pthread_setspecific(PL_thr_key, (void *)(t)))) \
332 Perl_croak_nocontext("panic: pthread_setspecific (%d) [%s:%d]", \
333 _eC_, __FILE__, __LINE__); \
334 } STMT_END
335 #endif /* PERL_SET_CONTEXT */
337 #ifndef INIT_THREADS
338 # ifdef NEED_PTHREAD_INIT
339 # define INIT_THREADS pthread_init()
340 # endif
341 #endif
343 #ifndef ALLOC_THREAD_KEY
344 # define ALLOC_THREAD_KEY \
345 STMT_START { \
346 if (pthread_key_create(&PL_thr_key, 0)) { \
347 PERL_UNUSED_RESULT(write(2, STR_WITH_LEN("panic: pthread_key_create failed\n"))); \
348 exit(1); \
349 } \
350 } STMT_END
351 #endif
353 #ifndef FREE_THREAD_KEY
354 # define FREE_THREAD_KEY \
355 STMT_START { \
356 pthread_key_delete(PL_thr_key); \
357 } STMT_END
358 #endif
360 #ifndef PTHREAD_ATFORK
361 # ifdef HAS_PTHREAD_ATFORK
362 # define PTHREAD_ATFORK(prepare,parent,child) \
363 pthread_atfork(prepare,parent,child)
364 # else
365 # define PTHREAD_ATFORK(prepare,parent,child) \
366 NOOP
367 # endif
368 #endif
370 #ifndef THREAD_RET_TYPE
371 # define THREAD_RET_TYPE void *
372 # define THREAD_RET_CAST(p) ((void *)(p))
373 #endif /* THREAD_RET */
375 # define LOCK_DOLLARZERO_MUTEX MUTEX_LOCK(&PL_dollarzero_mutex)
376 # define UNLOCK_DOLLARZERO_MUTEX MUTEX_UNLOCK(&PL_dollarzero_mutex)
378 #endif /* USE_ITHREADS */
380 #ifndef MUTEX_LOCK
381 # define MUTEX_LOCK(m)
382 #endif
384 #ifndef MUTEX_UNLOCK
385 # define MUTEX_UNLOCK(m)
386 #endif
388 #ifndef MUTEX_INIT
389 # define MUTEX_INIT(m)
390 #endif
392 #ifndef MUTEX_DESTROY
393 # define MUTEX_DESTROY(m)
394 #endif
396 #ifndef COND_INIT
397 # define COND_INIT(c)
398 #endif
400 #ifndef COND_SIGNAL
401 # define COND_SIGNAL(c)
402 #endif
404 #ifndef COND_BROADCAST
405 # define COND_BROADCAST(c)
406 #endif
408 #ifndef COND_WAIT
409 # define COND_WAIT(c, m)
410 #endif
412 #ifndef COND_DESTROY
413 # define COND_DESTROY(c)
414 #endif
416 #ifndef LOCK_DOLLARZERO_MUTEX
417 # define LOCK_DOLLARZERO_MUTEX
418 #endif
420 #ifndef UNLOCK_DOLLARZERO_MUTEX
421 # define UNLOCK_DOLLARZERO_MUTEX
422 #endif
424 /* THR, SET_THR, and dTHR are there for compatibility with old versions */
425 #ifndef THR
426 # define THR PERL_GET_THX
427 #endif
429 #ifndef SET_THR
430 # define SET_THR(t) PERL_SET_THX(t)
431 #endif
433 #ifndef dTHR
434 # define dTHR dNOOP
435 #endif
437 #ifndef INIT_THREADS
438 # define INIT_THREADS NOOP
439 #endif
441 /*
442 * ex: set ts=8 sts=4 sw=4 et:
443 */