Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / nptl / pthread.h
blob70ff250a17045fa4bfee55faa1f660148d412894
1 /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #ifndef _PTHREAD_H
19 #define _PTHREAD_H 1
21 #include <features.h>
22 #include <endian.h>
23 #include <sched.h>
24 #include <time.h>
26 #include <bits/pthreadtypes.h>
27 #include <bits/setjmp.h>
28 #include <bits/wordsize.h>
31 /* Detach state. */
32 enum
34 PTHREAD_CREATE_JOINABLE,
35 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
36 PTHREAD_CREATE_DETACHED
37 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
41 /* Mutex types. */
42 enum
44 PTHREAD_MUTEX_TIMED_NP,
45 PTHREAD_MUTEX_RECURSIVE_NP,
46 PTHREAD_MUTEX_ERRORCHECK_NP,
47 PTHREAD_MUTEX_ADAPTIVE_NP
48 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
50 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP,
51 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
52 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
53 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
54 #endif
55 #ifdef __USE_GNU
56 /* For compatibility. */
57 , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP
58 #endif
62 #ifdef __USE_XOPEN2K
63 /* Robust mutex or not flags. */
64 enum
66 PTHREAD_MUTEX_STALLED,
67 PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED,
68 PTHREAD_MUTEX_ROBUST,
69 PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST
71 #endif
74 #if defined __USE_POSIX199506 || defined __USE_UNIX98
75 /* Mutex protocols. */
76 enum
78 PTHREAD_PRIO_NONE,
79 PTHREAD_PRIO_INHERIT,
80 PTHREAD_PRIO_PROTECT
82 #endif
85 #ifdef __PTHREAD_MUTEX_HAVE_PREV
86 # define PTHREAD_MUTEX_INITIALIZER \
87 { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } }
88 # ifdef __USE_GNU
89 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
90 { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __PTHREAD_SPINS, { 0, 0 } } }
91 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
92 { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __PTHREAD_SPINS, { 0, 0 } } }
93 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
94 { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } }
95 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
96 { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } }
98 # endif
99 #else
100 # define PTHREAD_MUTEX_INITIALIZER \
101 { { 0, 0, 0, 0, 0, { __PTHREAD_SPINS } } }
102 # ifdef __USE_GNU
103 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
104 { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { __PTHREAD_SPINS } } }
105 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
106 { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { __PTHREAD_SPINS } } }
107 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
108 { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { __PTHREAD_SPINS } } }
110 # endif
111 #endif
114 /* Read-write lock types. */
115 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
116 enum
118 PTHREAD_RWLOCK_PREFER_READER_NP,
119 PTHREAD_RWLOCK_PREFER_WRITER_NP,
120 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,
121 PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP
124 /* Define __PTHREAD_RWLOCK_INT_FLAGS_SHARED to 1 if pthread_rwlock_t
125 has the shared field. All 64-bit architectures have the shared field
126 in pthread_rwlock_t. */
127 #ifndef __PTHREAD_RWLOCK_INT_FLAGS_SHARED
128 # if __WORDSIZE == 64
129 # define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1
130 # endif
131 #endif
133 /* Read-write lock initializers. */
134 # define PTHREAD_RWLOCK_INITIALIZER \
135 { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } }
136 # ifdef __USE_GNU
137 # ifdef __PTHREAD_RWLOCK_INT_FLAGS_SHARED
138 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
139 { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, \
140 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
141 # else
142 # if __BYTE_ORDER == __LITTLE_ENDIAN
143 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
144 { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \
145 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } }
146 # else
147 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
148 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\
149 0 } }
150 # endif
151 # endif
152 # endif
153 #endif /* Unix98 or XOpen2K */
156 /* Scheduler inheritance. */
157 enum
159 PTHREAD_INHERIT_SCHED,
160 #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED
161 PTHREAD_EXPLICIT_SCHED
162 #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED
166 /* Scope handling. */
167 enum
169 PTHREAD_SCOPE_SYSTEM,
170 #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
171 PTHREAD_SCOPE_PROCESS
172 #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
176 /* Process shared or private flag. */
177 enum
179 PTHREAD_PROCESS_PRIVATE,
180 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
181 PTHREAD_PROCESS_SHARED
182 #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
187 /* Conditional variable handling. */
188 #define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
191 /* Cleanup buffers */
192 struct _pthread_cleanup_buffer
194 void (*__routine) (void *); /* Function to call. */
195 void *__arg; /* Its argument. */
196 int __canceltype; /* Saved cancellation type. */
197 struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */
200 /* Cancellation */
201 enum
203 PTHREAD_CANCEL_ENABLE,
204 #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
205 PTHREAD_CANCEL_DISABLE
206 #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
208 enum
210 PTHREAD_CANCEL_DEFERRED,
211 #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
212 PTHREAD_CANCEL_ASYNCHRONOUS
213 #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
215 #define PTHREAD_CANCELED ((void *) -1)
218 /* Single execution handling. */
219 #define PTHREAD_ONCE_INIT 0
222 #ifdef __USE_XOPEN2K
223 /* Value returned by 'pthread_barrier_wait' for one of the threads after
224 the required number of threads have called this function.
225 -1 is distinct from 0 and all errno constants */
226 # define PTHREAD_BARRIER_SERIAL_THREAD -1
227 #endif
230 __BEGIN_DECLS
232 /* Create a new thread, starting with execution of START-ROUTINE
233 getting passed ARG. Creation attributed come from ATTR. The new
234 handle is stored in *NEWTHREAD. */
235 extern int pthread_create (pthread_t *__restrict __newthread,
236 const pthread_attr_t *__restrict __attr,
237 void *(*__start_routine) (void *),
238 void *__restrict __arg) __THROWNL __nonnull ((1, 3));
240 /* Terminate calling thread.
242 The registered cleanup handlers are called via exception handling
243 so we cannot mark this function with __THROW.*/
244 extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__));
246 /* Make calling thread wait for termination of the thread TH. The
247 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
248 is not NULL.
250 This function is a cancellation point and therefore not marked with
251 __THROW. */
252 extern int pthread_join (pthread_t __th, void **__thread_return);
254 #ifdef __USE_GNU
255 /* Check whether thread TH has terminated. If yes return the status of
256 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */
257 extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
259 /* Make calling thread wait for termination of the thread TH, but only
260 until TIMEOUT. The exit status of the thread is stored in
261 *THREAD_RETURN, if THREAD_RETURN is not NULL.
263 This function is a cancellation point and therefore not marked with
264 __THROW. */
265 extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
266 const struct timespec *__abstime);
267 #endif
269 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
270 The resources of TH will therefore be freed immediately when it
271 terminates, instead of waiting for another thread to perform PTHREAD_JOIN
272 on it. */
273 extern int pthread_detach (pthread_t __th) __THROW;
276 /* Obtain the identifier of the current thread. */
277 extern pthread_t pthread_self (void) __THROW __attribute__ ((__const__));
279 /* Compare two thread identifiers. */
280 extern int pthread_equal (pthread_t __thread1, pthread_t __thread2)
281 __THROW __attribute__ ((__const__));
284 /* Thread attribute handling. */
286 /* Initialize thread attribute *ATTR with default attributes
287 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER,
288 no user-provided stack). */
289 extern int pthread_attr_init (pthread_attr_t *__attr) __THROW __nonnull ((1));
291 /* Destroy thread attribute *ATTR. */
292 extern int pthread_attr_destroy (pthread_attr_t *__attr)
293 __THROW __nonnull ((1));
295 /* Get detach state attribute. */
296 extern int pthread_attr_getdetachstate (const pthread_attr_t *__attr,
297 int *__detachstate)
298 __THROW __nonnull ((1, 2));
300 /* Set detach state attribute. */
301 extern int pthread_attr_setdetachstate (pthread_attr_t *__attr,
302 int __detachstate)
303 __THROW __nonnull ((1));
306 /* Get the size of the guard area created for stack overflow protection. */
307 extern int pthread_attr_getguardsize (const pthread_attr_t *__attr,
308 size_t *__guardsize)
309 __THROW __nonnull ((1, 2));
311 /* Set the size of the guard area created for stack overflow protection. */
312 extern int pthread_attr_setguardsize (pthread_attr_t *__attr,
313 size_t __guardsize)
314 __THROW __nonnull ((1));
317 /* Return in *PARAM the scheduling parameters of *ATTR. */
318 extern int pthread_attr_getschedparam (const pthread_attr_t *__restrict __attr,
319 struct sched_param *__restrict __param)
320 __THROW __nonnull ((1, 2));
322 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */
323 extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr,
324 const struct sched_param *__restrict
325 __param) __THROW __nonnull ((1, 2));
327 /* Return in *POLICY the scheduling policy of *ATTR. */
328 extern int pthread_attr_getschedpolicy (const pthread_attr_t *__restrict
329 __attr, int *__restrict __policy)
330 __THROW __nonnull ((1, 2));
332 /* Set scheduling policy in *ATTR according to POLICY. */
333 extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy)
334 __THROW __nonnull ((1));
336 /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */
337 extern int pthread_attr_getinheritsched (const pthread_attr_t *__restrict
338 __attr, int *__restrict __inherit)
339 __THROW __nonnull ((1, 2));
341 /* Set scheduling inheritance mode in *ATTR according to INHERIT. */
342 extern int pthread_attr_setinheritsched (pthread_attr_t *__attr,
343 int __inherit)
344 __THROW __nonnull ((1));
347 /* Return in *SCOPE the scheduling contention scope of *ATTR. */
348 extern int pthread_attr_getscope (const pthread_attr_t *__restrict __attr,
349 int *__restrict __scope)
350 __THROW __nonnull ((1, 2));
352 /* Set scheduling contention scope in *ATTR according to SCOPE. */
353 extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope)
354 __THROW __nonnull ((1));
356 /* Return the previously set address for the stack. */
357 extern int pthread_attr_getstackaddr (const pthread_attr_t *__restrict
358 __attr, void **__restrict __stackaddr)
359 __THROW __nonnull ((1, 2)) __attribute_deprecated__;
361 /* Set the starting address of the stack of the thread to be created.
362 Depending on whether the stack grows up or down the value must either
363 be higher or lower than all the address in the memory block. The
364 minimal size of the block must be PTHREAD_STACK_MIN. */
365 extern int pthread_attr_setstackaddr (pthread_attr_t *__attr,
366 void *__stackaddr)
367 __THROW __nonnull ((1)) __attribute_deprecated__;
369 /* Return the currently used minimal stack size. */
370 extern int pthread_attr_getstacksize (const pthread_attr_t *__restrict
371 __attr, size_t *__restrict __stacksize)
372 __THROW __nonnull ((1, 2));
374 /* Add information about the minimum stack size needed for the thread
375 to be started. This size must never be less than PTHREAD_STACK_MIN
376 and must also not exceed the system limits. */
377 extern int pthread_attr_setstacksize (pthread_attr_t *__attr,
378 size_t __stacksize)
379 __THROW __nonnull ((1));
381 #ifdef __USE_XOPEN2K
382 /* Return the previously set address for the stack. */
383 extern int pthread_attr_getstack (const pthread_attr_t *__restrict __attr,
384 void **__restrict __stackaddr,
385 size_t *__restrict __stacksize)
386 __THROW __nonnull ((1, 2, 3));
388 /* The following two interfaces are intended to replace the last two. They
389 require setting the address as well as the size since only setting the
390 address will make the implementation on some architectures impossible. */
391 extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr,
392 size_t __stacksize) __THROW __nonnull ((1));
393 #endif
395 #ifdef __USE_GNU
396 /* Thread created with attribute ATTR will be limited to run only on
397 the processors represented in CPUSET. */
398 extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr,
399 size_t __cpusetsize,
400 const cpu_set_t *__cpuset)
401 __THROW __nonnull ((1, 3));
403 /* Get bit set in CPUSET representing the processors threads created with
404 ATTR can run on. */
405 extern int pthread_attr_getaffinity_np (const pthread_attr_t *__attr,
406 size_t __cpusetsize,
407 cpu_set_t *__cpuset)
408 __THROW __nonnull ((1, 3));
410 /* Get the default attributes used by pthread_create in this process. */
411 extern int pthread_getattr_default_np (pthread_attr_t *__attr)
412 __THROW __nonnull ((1));
414 /* Set the default attributes to be used by pthread_create in this
415 process. */
416 extern int pthread_setattr_default_np (const pthread_attr_t *__attr)
417 __THROW __nonnull ((1));
419 /* Initialize thread attribute *ATTR with attributes corresponding to the
420 already running thread TH. It shall be called on uninitialized ATTR
421 and destroyed with pthread_attr_destroy when no longer needed. */
422 extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr)
423 __THROW __nonnull ((2));
424 #endif
427 /* Functions for scheduling control. */
429 /* Set the scheduling parameters for TARGET_THREAD according to POLICY
430 and *PARAM. */
431 extern int pthread_setschedparam (pthread_t __target_thread, int __policy,
432 const struct sched_param *__param)
433 __THROW __nonnull ((3));
435 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */
436 extern int pthread_getschedparam (pthread_t __target_thread,
437 int *__restrict __policy,
438 struct sched_param *__restrict __param)
439 __THROW __nonnull ((2, 3));
441 /* Set the scheduling priority for TARGET_THREAD. */
442 extern int pthread_setschedprio (pthread_t __target_thread, int __prio)
443 __THROW;
446 #ifdef __USE_GNU
447 /* Get thread name visible in the kernel and its interfaces. */
448 extern int pthread_getname_np (pthread_t __target_thread, char *__buf,
449 size_t __buflen)
450 __THROW __nonnull ((2));
452 /* Set thread name visible in the kernel and its interfaces. */
453 extern int pthread_setname_np (pthread_t __target_thread, const char *__name)
454 __THROW __nonnull ((2));
455 #endif
458 #ifdef __USE_UNIX98
459 /* Determine level of concurrency. */
460 extern int pthread_getconcurrency (void) __THROW;
462 /* Set new concurrency level to LEVEL. */
463 extern int pthread_setconcurrency (int __level) __THROW;
464 #endif
466 #ifdef __USE_GNU
467 /* Yield the processor to another thread or process.
468 This function is similar to the POSIX `sched_yield' function but
469 might be differently implemented in the case of a m-on-n thread
470 implementation. */
471 extern int pthread_yield (void) __THROW;
474 /* Limit specified thread TH to run only on the processors represented
475 in CPUSET. */
476 extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
477 const cpu_set_t *__cpuset)
478 __THROW __nonnull ((3));
480 /* Get bit set in CPUSET representing the processors TH can run on. */
481 extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
482 cpu_set_t *__cpuset)
483 __THROW __nonnull ((3));
484 #endif
487 /* Functions for handling initialization. */
489 /* Guarantee that the initialization function INIT_ROUTINE will be called
490 only once, even if pthread_once is executed several times with the
491 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or
492 extern variable initialized to PTHREAD_ONCE_INIT.
494 The initialization functions might throw exception which is why
495 this function is not marked with __THROW. */
496 extern int pthread_once (pthread_once_t *__once_control,
497 void (*__init_routine) (void)) __nonnull ((1, 2));
500 /* Functions for handling cancellation.
502 Note that these functions are explicitly not marked to not throw an
503 exception in C++ code. If cancellation is implemented by unwinding
504 this is necessary to have the compiler generate the unwind information. */
506 /* Set cancelability state of current thread to STATE, returning old
507 state in *OLDSTATE if OLDSTATE is not NULL. */
508 extern int pthread_setcancelstate (int __state, int *__oldstate);
510 /* Set cancellation state of current thread to TYPE, returning the old
511 type in *OLDTYPE if OLDTYPE is not NULL. */
512 extern int pthread_setcanceltype (int __type, int *__oldtype);
514 /* Cancel THREAD immediately or at the next possibility. */
515 extern int pthread_cancel (pthread_t __th);
517 /* Test for pending cancellation for the current thread and terminate
518 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been
519 cancelled. */
520 extern void pthread_testcancel (void);
523 /* Cancellation handling with integration into exception handling. */
525 typedef struct
527 struct
529 __jmp_buf __cancel_jmp_buf;
530 int __mask_was_saved;
531 } __cancel_jmp_buf[1];
532 void *__pad[4];
533 } __pthread_unwind_buf_t __attribute__ ((__aligned__));
535 /* No special attributes by default. */
536 #ifndef __cleanup_fct_attribute
537 # define __cleanup_fct_attribute
538 #endif
541 /* Structure to hold the cleanup handler information. */
542 struct __pthread_cleanup_frame
544 void (*__cancel_routine) (void *);
545 void *__cancel_arg;
546 int __do_it;
547 int __cancel_type;
550 #if defined __GNUC__ && defined __EXCEPTIONS
551 # ifdef __cplusplus
552 /* Class to handle cancellation handler invocation. */
553 class __pthread_cleanup_class
555 void (*__cancel_routine) (void *);
556 void *__cancel_arg;
557 int __do_it;
558 int __cancel_type;
560 public:
561 __pthread_cleanup_class (void (*__fct) (void *), void *__arg)
562 : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { }
563 ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); }
564 void __setdoit (int __newval) { __do_it = __newval; }
565 void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED,
566 &__cancel_type); }
567 void __restore () const { pthread_setcanceltype (__cancel_type, 0); }
570 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
571 when the thread is canceled or calls pthread_exit. ROUTINE will also
572 be called with arguments ARG when the matching pthread_cleanup_pop
573 is executed with non-zero EXECUTE argument.
575 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
576 be used in matching pairs at the same nesting level of braces. */
577 # define pthread_cleanup_push(routine, arg) \
578 do { \
579 __pthread_cleanup_class __clframe (routine, arg)
581 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
582 If EXECUTE is non-zero, the handler function is called. */
583 # define pthread_cleanup_pop(execute) \
584 __clframe.__setdoit (execute); \
585 } while (0)
587 # ifdef __USE_GNU
588 /* Install a cleanup handler as pthread_cleanup_push does, but also
589 saves the current cancellation type and sets it to deferred
590 cancellation. */
591 # define pthread_cleanup_push_defer_np(routine, arg) \
592 do { \
593 __pthread_cleanup_class __clframe (routine, arg); \
594 __clframe.__defer ()
596 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
597 restores the cancellation type that was in effect when the matching
598 pthread_cleanup_push_defer was called. */
599 # define pthread_cleanup_pop_restore_np(execute) \
600 __clframe.__restore (); \
601 __clframe.__setdoit (execute); \
602 } while (0)
603 # endif
604 # else
605 /* Function called to call the cleanup handler. As an extern inline
606 function the compiler is free to decide inlining the change when
607 needed or fall back on the copy which must exist somewhere
608 else. */
609 __extern_inline void
610 __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
612 if (__frame->__do_it)
613 __frame->__cancel_routine (__frame->__cancel_arg);
616 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
617 when the thread is canceled or calls pthread_exit. ROUTINE will also
618 be called with arguments ARG when the matching pthread_cleanup_pop
619 is executed with non-zero EXECUTE argument.
621 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
622 be used in matching pairs at the same nesting level of braces. */
623 # define pthread_cleanup_push(routine, arg) \
624 do { \
625 struct __pthread_cleanup_frame __clframe \
626 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
627 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
628 .__do_it = 1 };
630 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
631 If EXECUTE is non-zero, the handler function is called. */
632 # define pthread_cleanup_pop(execute) \
633 __clframe.__do_it = (execute); \
634 } while (0)
636 # ifdef __USE_GNU
637 /* Install a cleanup handler as pthread_cleanup_push does, but also
638 saves the current cancellation type and sets it to deferred
639 cancellation. */
640 # define pthread_cleanup_push_defer_np(routine, arg) \
641 do { \
642 struct __pthread_cleanup_frame __clframe \
643 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
644 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \
645 .__do_it = 1 }; \
646 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
647 &__clframe.__cancel_type)
649 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
650 restores the cancellation type that was in effect when the matching
651 pthread_cleanup_push_defer was called. */
652 # define pthread_cleanup_pop_restore_np(execute) \
653 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
654 __clframe.__do_it = (execute); \
655 } while (0)
656 # endif
657 # endif
658 #else
659 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
660 when the thread is canceled or calls pthread_exit. ROUTINE will also
661 be called with arguments ARG when the matching pthread_cleanup_pop
662 is executed with non-zero EXECUTE argument.
664 pthread_cleanup_push and pthread_cleanup_pop are macros and must always
665 be used in matching pairs at the same nesting level of braces. */
666 # define pthread_cleanup_push(routine, arg) \
667 do { \
668 __pthread_unwind_buf_t __cancel_buf; \
669 void (*__cancel_routine) (void *) = (routine); \
670 void *__cancel_arg = (arg); \
671 int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
672 __cancel_buf.__cancel_jmp_buf, 0); \
673 if (__glibc_unlikely (__not_first_call)) \
675 __cancel_routine (__cancel_arg); \
676 __pthread_unwind_next (&__cancel_buf); \
677 /* NOTREACHED */ \
680 __pthread_register_cancel (&__cancel_buf); \
681 do {
682 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
683 __cleanup_fct_attribute;
685 /* Remove a cleanup handler installed by the matching pthread_cleanup_push.
686 If EXECUTE is non-zero, the handler function is called. */
687 # define pthread_cleanup_pop(execute) \
688 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
689 } while (0); \
690 __pthread_unregister_cancel (&__cancel_buf); \
691 if (execute) \
692 __cancel_routine (__cancel_arg); \
693 } while (0)
694 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
695 __cleanup_fct_attribute;
697 # ifdef __USE_GNU
698 /* Install a cleanup handler as pthread_cleanup_push does, but also
699 saves the current cancellation type and sets it to deferred
700 cancellation. */
701 # define pthread_cleanup_push_defer_np(routine, arg) \
702 do { \
703 __pthread_unwind_buf_t __cancel_buf; \
704 void (*__cancel_routine) (void *) = (routine); \
705 void *__cancel_arg = (arg); \
706 int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \
707 __cancel_buf.__cancel_jmp_buf, 0); \
708 if (__glibc_unlikely (__not_first_call)) \
710 __cancel_routine (__cancel_arg); \
711 __pthread_unwind_next (&__cancel_buf); \
712 /* NOTREACHED */ \
715 __pthread_register_cancel_defer (&__cancel_buf); \
716 do {
717 extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
718 __cleanup_fct_attribute;
720 /* Remove a cleanup handler as pthread_cleanup_pop does, but also
721 restores the cancellation type that was in effect when the matching
722 pthread_cleanup_push_defer was called. */
723 # define pthread_cleanup_pop_restore_np(execute) \
724 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\
725 } while (0); \
726 __pthread_unregister_cancel_restore (&__cancel_buf); \
727 if (execute) \
728 __cancel_routine (__cancel_arg); \
729 } while (0)
730 extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
731 __cleanup_fct_attribute;
732 # endif
734 /* Internal interface to initiate cleanup. */
735 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
736 __cleanup_fct_attribute __attribute__ ((__noreturn__))
737 # ifndef SHARED
738 __attribute__ ((__weak__))
739 # endif
741 #endif
743 /* Function used in the macros. */
744 struct __jmp_buf_tag;
745 extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
748 /* Mutex handling. */
750 /* Initialize a mutex. */
751 extern int pthread_mutex_init (pthread_mutex_t *__mutex,
752 const pthread_mutexattr_t *__mutexattr)
753 __THROW __nonnull ((1));
755 /* Destroy a mutex. */
756 extern int pthread_mutex_destroy (pthread_mutex_t *__mutex)
757 __THROW __nonnull ((1));
759 /* Try locking a mutex. */
760 extern int pthread_mutex_trylock (pthread_mutex_t *__mutex)
761 __THROWNL __nonnull ((1));
763 /* Lock a mutex. */
764 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
765 __THROWNL __nonnull ((1));
767 #ifdef __USE_XOPEN2K
768 /* Wait until lock becomes available, or specified time passes. */
769 extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
770 const struct timespec *__restrict
771 __abstime) __THROWNL __nonnull ((1, 2));
772 #endif
774 /* Unlock a mutex. */
775 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
776 __THROWNL __nonnull ((1));
779 /* Get the priority ceiling of MUTEX. */
780 extern int pthread_mutex_getprioceiling (const pthread_mutex_t *
781 __restrict __mutex,
782 int *__restrict __prioceiling)
783 __THROW __nonnull ((1, 2));
785 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old
786 priority ceiling value in *OLD_CEILING. */
787 extern int pthread_mutex_setprioceiling (pthread_mutex_t *__restrict __mutex,
788 int __prioceiling,
789 int *__restrict __old_ceiling)
790 __THROW __nonnull ((1, 3));
793 #ifdef __USE_XOPEN2K8
794 /* Declare the state protected by MUTEX as consistent. */
795 extern int pthread_mutex_consistent (pthread_mutex_t *__mutex)
796 __THROW __nonnull ((1));
797 # ifdef __USE_GNU
798 extern int pthread_mutex_consistent_np (pthread_mutex_t *__mutex)
799 __THROW __nonnull ((1));
800 # endif
801 #endif
804 /* Functions for handling mutex attributes. */
806 /* Initialize mutex attribute object ATTR with default attributes
807 (kind is PTHREAD_MUTEX_TIMED_NP). */
808 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr)
809 __THROW __nonnull ((1));
811 /* Destroy mutex attribute object ATTR. */
812 extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr)
813 __THROW __nonnull ((1));
815 /* Get the process-shared flag of the mutex attribute ATTR. */
816 extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t *
817 __restrict __attr,
818 int *__restrict __pshared)
819 __THROW __nonnull ((1, 2));
821 /* Set the process-shared flag of the mutex attribute ATTR. */
822 extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr,
823 int __pshared)
824 __THROW __nonnull ((1));
826 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8
827 /* Return in *KIND the mutex kind attribute in *ATTR. */
828 extern int pthread_mutexattr_gettype (const pthread_mutexattr_t *__restrict
829 __attr, int *__restrict __kind)
830 __THROW __nonnull ((1, 2));
832 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL,
833 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or
834 PTHREAD_MUTEX_DEFAULT). */
835 extern int pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind)
836 __THROW __nonnull ((1));
837 #endif
839 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */
840 extern int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *
841 __restrict __attr,
842 int *__restrict __protocol)
843 __THROW __nonnull ((1, 2));
845 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
846 PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */
847 extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr,
848 int __protocol)
849 __THROW __nonnull ((1));
851 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */
852 extern int pthread_mutexattr_getprioceiling (const pthread_mutexattr_t *
853 __restrict __attr,
854 int *__restrict __prioceiling)
855 __THROW __nonnull ((1, 2));
857 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */
858 extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr,
859 int __prioceiling)
860 __THROW __nonnull ((1));
862 #ifdef __USE_XOPEN2K
863 /* Get the robustness flag of the mutex attribute ATTR. */
864 extern int pthread_mutexattr_getrobust (const pthread_mutexattr_t *__attr,
865 int *__robustness)
866 __THROW __nonnull ((1, 2));
867 # ifdef __USE_GNU
868 extern int pthread_mutexattr_getrobust_np (const pthread_mutexattr_t *__attr,
869 int *__robustness)
870 __THROW __nonnull ((1, 2));
871 # endif
873 /* Set the robustness flag of the mutex attribute ATTR. */
874 extern int pthread_mutexattr_setrobust (pthread_mutexattr_t *__attr,
875 int __robustness)
876 __THROW __nonnull ((1));
877 # ifdef __USE_GNU
878 extern int pthread_mutexattr_setrobust_np (pthread_mutexattr_t *__attr,
879 int __robustness)
880 __THROW __nonnull ((1));
881 # endif
882 #endif
885 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
886 /* Functions for handling read-write locks. */
888 /* Initialize read-write lock RWLOCK using attributes ATTR, or use
889 the default values if later is NULL. */
890 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock,
891 const pthread_rwlockattr_t *__restrict
892 __attr) __THROW __nonnull ((1));
894 /* Destroy read-write lock RWLOCK. */
895 extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock)
896 __THROW __nonnull ((1));
898 /* Acquire read lock for RWLOCK. */
899 extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock)
900 __THROWNL __nonnull ((1));
902 /* Try to acquire read lock for RWLOCK. */
903 extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
904 __THROWNL __nonnull ((1));
906 # ifdef __USE_XOPEN2K
907 /* Try to acquire read lock for RWLOCK or return after specfied time. */
908 extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
909 const struct timespec *__restrict
910 __abstime) __THROWNL __nonnull ((1, 2));
911 # endif
913 /* Acquire write lock for RWLOCK. */
914 extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
915 __THROWNL __nonnull ((1));
917 /* Try to acquire write lock for RWLOCK. */
918 extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
919 __THROWNL __nonnull ((1));
921 # ifdef __USE_XOPEN2K
922 /* Try to acquire write lock for RWLOCK or return after specfied time. */
923 extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
924 const struct timespec *__restrict
925 __abstime) __THROWNL __nonnull ((1, 2));
926 # endif
928 /* Unlock RWLOCK. */
929 extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
930 __THROWNL __nonnull ((1));
933 /* Functions for handling read-write lock attributes. */
935 /* Initialize attribute object ATTR with default values. */
936 extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr)
937 __THROW __nonnull ((1));
939 /* Destroy attribute object ATTR. */
940 extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr)
941 __THROW __nonnull ((1));
943 /* Return current setting of process-shared attribute of ATTR in PSHARED. */
944 extern int pthread_rwlockattr_getpshared (const pthread_rwlockattr_t *
945 __restrict __attr,
946 int *__restrict __pshared)
947 __THROW __nonnull ((1, 2));
949 /* Set process-shared attribute of ATTR to PSHARED. */
950 extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr,
951 int __pshared)
952 __THROW __nonnull ((1));
954 /* Return current setting of reader/writer preference. */
955 extern int pthread_rwlockattr_getkind_np (const pthread_rwlockattr_t *
956 __restrict __attr,
957 int *__restrict __pref)
958 __THROW __nonnull ((1, 2));
960 /* Set reader/write preference. */
961 extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr,
962 int __pref) __THROW __nonnull ((1));
963 #endif
966 /* Functions for handling conditional variables. */
968 /* Initialize condition variable COND using attributes ATTR, or use
969 the default values if later is NULL. */
970 extern int pthread_cond_init (pthread_cond_t *__restrict __cond,
971 const pthread_condattr_t *__restrict __cond_attr)
972 __THROW __nonnull ((1));
974 /* Destroy condition variable COND. */
975 extern int pthread_cond_destroy (pthread_cond_t *__cond)
976 __THROW __nonnull ((1));
978 /* Wake up one thread waiting for condition variable COND. */
979 extern int pthread_cond_signal (pthread_cond_t *__cond)
980 __THROWNL __nonnull ((1));
982 /* Wake up all threads waiting for condition variables COND. */
983 extern int pthread_cond_broadcast (pthread_cond_t *__cond)
984 __THROWNL __nonnull ((1));
986 /* Wait for condition variable COND to be signaled or broadcast.
987 MUTEX is assumed to be locked before.
989 This function is a cancellation point and therefore not marked with
990 __THROW. */
991 extern int pthread_cond_wait (pthread_cond_t *__restrict __cond,
992 pthread_mutex_t *__restrict __mutex)
993 __nonnull ((1, 2));
995 /* Wait for condition variable COND to be signaled or broadcast until
996 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an
997 absolute time specification; zero is the beginning of the epoch
998 (00:00:00 GMT, January 1, 1970).
1000 This function is a cancellation point and therefore not marked with
1001 __THROW. */
1002 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
1003 pthread_mutex_t *__restrict __mutex,
1004 const struct timespec *__restrict __abstime)
1005 __nonnull ((1, 2, 3));
1007 /* Functions for handling condition variable attributes. */
1009 /* Initialize condition variable attribute ATTR. */
1010 extern int pthread_condattr_init (pthread_condattr_t *__attr)
1011 __THROW __nonnull ((1));
1013 /* Destroy condition variable attribute ATTR. */
1014 extern int pthread_condattr_destroy (pthread_condattr_t *__attr)
1015 __THROW __nonnull ((1));
1017 /* Get the process-shared flag of the condition variable attribute ATTR. */
1018 extern int pthread_condattr_getpshared (const pthread_condattr_t *
1019 __restrict __attr,
1020 int *__restrict __pshared)
1021 __THROW __nonnull ((1, 2));
1023 /* Set the process-shared flag of the condition variable attribute ATTR. */
1024 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
1025 int __pshared) __THROW __nonnull ((1));
1027 #ifdef __USE_XOPEN2K
1028 /* Get the clock selected for the condition variable attribute ATTR. */
1029 extern int pthread_condattr_getclock (const pthread_condattr_t *
1030 __restrict __attr,
1031 __clockid_t *__restrict __clock_id)
1032 __THROW __nonnull ((1, 2));
1034 /* Set the clock selected for the condition variable attribute ATTR. */
1035 extern int pthread_condattr_setclock (pthread_condattr_t *__attr,
1036 __clockid_t __clock_id)
1037 __THROW __nonnull ((1));
1038 #endif
1041 #ifdef __USE_XOPEN2K
1042 /* Functions to handle spinlocks. */
1044 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can
1045 be shared between different processes. */
1046 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared)
1047 __THROW __nonnull ((1));
1049 /* Destroy the spinlock LOCK. */
1050 extern int pthread_spin_destroy (pthread_spinlock_t *__lock)
1051 __THROW __nonnull ((1));
1053 /* Wait until spinlock LOCK is retrieved. */
1054 extern int pthread_spin_lock (pthread_spinlock_t *__lock)
1055 __THROWNL __nonnull ((1));
1057 /* Try to lock spinlock LOCK. */
1058 extern int pthread_spin_trylock (pthread_spinlock_t *__lock)
1059 __THROWNL __nonnull ((1));
1061 /* Release spinlock LOCK. */
1062 extern int pthread_spin_unlock (pthread_spinlock_t *__lock)
1063 __THROWNL __nonnull ((1));
1066 /* Functions to handle barriers. */
1068 /* Initialize BARRIER with the attributes in ATTR. The barrier is
1069 opened when COUNT waiters arrived. */
1070 extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier,
1071 const pthread_barrierattr_t *__restrict
1072 __attr, unsigned int __count)
1073 __THROW __nonnull ((1));
1075 /* Destroy a previously dynamically initialized barrier BARRIER. */
1076 extern int pthread_barrier_destroy (pthread_barrier_t *__barrier)
1077 __THROW __nonnull ((1));
1079 /* Wait on barrier BARRIER. */
1080 extern int pthread_barrier_wait (pthread_barrier_t *__barrier)
1081 __THROWNL __nonnull ((1));
1084 /* Initialize barrier attribute ATTR. */
1085 extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr)
1086 __THROW __nonnull ((1));
1088 /* Destroy previously dynamically initialized barrier attribute ATTR. */
1089 extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr)
1090 __THROW __nonnull ((1));
1092 /* Get the process-shared flag of the barrier attribute ATTR. */
1093 extern int pthread_barrierattr_getpshared (const pthread_barrierattr_t *
1094 __restrict __attr,
1095 int *__restrict __pshared)
1096 __THROW __nonnull ((1, 2));
1098 /* Set the process-shared flag of the barrier attribute ATTR. */
1099 extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr,
1100 int __pshared)
1101 __THROW __nonnull ((1));
1102 #endif
1105 /* Functions for handling thread-specific data. */
1107 /* Create a key value identifying a location in the thread-specific
1108 data area. Each thread maintains a distinct thread-specific data
1109 area. DESTR_FUNCTION, if non-NULL, is called with the value
1110 associated to that key when the key is destroyed.
1111 DESTR_FUNCTION is not called if the value associated is NULL when
1112 the key is destroyed. */
1113 extern int pthread_key_create (pthread_key_t *__key,
1114 void (*__destr_function) (void *))
1115 __THROW __nonnull ((1));
1117 /* Destroy KEY. */
1118 extern int pthread_key_delete (pthread_key_t __key) __THROW;
1120 /* Return current value of the thread-specific data slot identified by KEY. */
1121 extern void *pthread_getspecific (pthread_key_t __key) __THROW;
1123 /* Store POINTER in the thread-specific data slot identified by KEY. */
1124 extern int pthread_setspecific (pthread_key_t __key,
1125 const void *__pointer) __THROW ;
1128 #ifdef __USE_XOPEN2K
1129 /* Get ID of CPU-time clock for thread THREAD_ID. */
1130 extern int pthread_getcpuclockid (pthread_t __thread_id,
1131 __clockid_t *__clock_id)
1132 __THROW __nonnull ((2));
1133 #endif
1136 /* Install handlers to be called when a new process is created with FORK.
1137 The PREPARE handler is called in the parent process just before performing
1138 FORK. The PARENT handler is called in the parent process just after FORK.
1139 The CHILD handler is called in the child process. Each of the three
1140 handlers can be NULL, meaning that no handler needs to be called at that
1141 point.
1142 PTHREAD_ATFORK can be called several times, in which case the PREPARE
1143 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1144 first called before FORK), and the PARENT and CHILD handlers are called
1145 in FIFO (first added, first called). */
1147 extern int pthread_atfork (void (*__prepare) (void),
1148 void (*__parent) (void),
1149 void (*__child) (void)) __THROW;
1152 #ifdef __USE_EXTERN_INLINES
1153 /* Optimizations. */
1154 __extern_inline int
1155 __NTH (pthread_equal (pthread_t __thread1, pthread_t __thread2))
1157 return __thread1 == __thread2;
1159 #endif
1161 __END_DECLS
1163 #endif /* pthread.h */