modernc.org/cc@v1.0.1/v2/headers/linux_386/usr/include/pthread.h (about) 1 /* Copyright (C) 2002-2018 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 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. 8 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. 13 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/>. */ 17 18 #ifndef _PTHREAD_H 19 #define _PTHREAD_H 1 20 21 #include <features.h> 22 #include <endian.h> 23 #include <sched.h> 24 #include <time.h> 25 26 #include <bits/pthreadtypes.h> 27 #include <bits/setjmp.h> 28 #include <bits/wordsize.h> 29 #include <bits/types/struct_timespec.h> 30 31 /* Detach state. */ 32 enum { 33 PTHREAD_CREATE_JOINABLE, 34 #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE 35 PTHREAD_CREATE_DETACHED 36 #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED 37 }; 38 39 /* Mutex types. */ 40 enum { 41 PTHREAD_MUTEX_TIMED_NP, 42 PTHREAD_MUTEX_RECURSIVE_NP, 43 PTHREAD_MUTEX_ERRORCHECK_NP, 44 PTHREAD_MUTEX_ADAPTIVE_NP 45 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 46 , 47 PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_TIMED_NP, 48 PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP, 49 PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP, 50 PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL 51 #endif 52 #ifdef __USE_GNU 53 /* For compatibility. */ 54 , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP 55 #endif 56 }; 57 58 #ifdef __USE_XOPEN2K 59 /* Robust mutex or not flags. */ 60 enum { 61 PTHREAD_MUTEX_STALLED, 62 PTHREAD_MUTEX_STALLED_NP = PTHREAD_MUTEX_STALLED, 63 PTHREAD_MUTEX_ROBUST, 64 PTHREAD_MUTEX_ROBUST_NP = PTHREAD_MUTEX_ROBUST 65 }; 66 #endif 67 68 #if defined __USE_POSIX199506 || defined __USE_UNIX98 69 /* Mutex protocols. */ 70 enum { 71 PTHREAD_PRIO_NONE, 72 PTHREAD_PRIO_INHERIT, 73 PTHREAD_PRIO_PROTECT 74 }; 75 #endif 76 77 #if __PTHREAD_MUTEX_HAVE_PREV 78 # define PTHREAD_MUTEX_INITIALIZER \ 79 { { 0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } } 80 # ifdef __USE_GNU 81 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ 82 { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } 83 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ 84 { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, __PTHREAD_SPINS, { 0, 0 } } } 85 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ 86 { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, __PTHREAD_SPINS, { 0, 0 } } } 87 88 # endif 89 #else 90 # define PTHREAD_MUTEX_INITIALIZER \ 91 { { 0, 0, 0, 0, 0, { __PTHREAD_SPINS } } } 92 # ifdef __USE_GNU 93 # define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ 94 { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0, { __PTHREAD_SPINS } } } 95 # define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ 96 { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0, { __PTHREAD_SPINS } } } 97 # define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \ 98 { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP, 0, { __PTHREAD_SPINS } } } 99 100 # endif 101 #endif 102 103 /* Read-write lock types. */ 104 #if defined __USE_UNIX98 || defined __USE_XOPEN2K 105 enum { 106 PTHREAD_RWLOCK_PREFER_READER_NP, 107 PTHREAD_RWLOCK_PREFER_WRITER_NP, 108 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, 109 PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP 110 }; 111 112 /* Define __PTHREAD_RWLOCK_INT_FLAGS_SHARED to 1 if pthread_rwlock_t 113 has the shared field. All 64-bit architectures have the shared field 114 in pthread_rwlock_t. */ 115 #ifndef __PTHREAD_RWLOCK_INT_FLAGS_SHARED 116 # if __WORDSIZE == 64 117 # define __PTHREAD_RWLOCK_INT_FLAGS_SHARED 1 118 # endif 119 #endif 120 121 /* Read-write lock initializers. */ 122 # define PTHREAD_RWLOCK_INITIALIZER \ 123 { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } } 124 # ifdef __USE_GNU 125 # ifdef __PTHREAD_RWLOCK_INT_FLAGS_SHARED 126 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ 127 { { 0, 0, 0, 0, 0, 0, 0, 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, \ 128 PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } } 129 # else 130 # if __BYTE_ORDER == __LITTLE_ENDIAN 131 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ 132 { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, \ 133 0, __PTHREAD_RWLOCK_ELISION_EXTRA, 0, 0 } } 134 # else 135 # define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \ 136 { { 0, 0, 0, 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP,\ 137 0 } } 138 # endif 139 # endif 140 # endif 141 #endif /* Unix98 or XOpen2K */ 142 143 /* Scheduler inheritance. */ 144 enum { 145 PTHREAD_INHERIT_SCHED, 146 #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED 147 PTHREAD_EXPLICIT_SCHED 148 #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED 149 }; 150 151 /* Scope handling. */ 152 enum { 153 PTHREAD_SCOPE_SYSTEM, 154 #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM 155 PTHREAD_SCOPE_PROCESS 156 #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS 157 }; 158 159 /* Process shared or private flag. */ 160 enum { 161 PTHREAD_PROCESS_PRIVATE, 162 #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE 163 PTHREAD_PROCESS_SHARED 164 #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED 165 }; 166 167 /* Conditional variable handling. */ 168 #define PTHREAD_COND_INITIALIZER { { {0}, {0}, {0, 0}, {0, 0}, 0, 0, {0, 0} } } 169 170 /* Cleanup buffers */ 171 struct _pthread_cleanup_buffer { 172 void (*__routine) (void *); /* Function to call. */ 173 void *__arg; /* Its argument. */ 174 int __canceltype; /* Saved cancellation type. */ 175 struct _pthread_cleanup_buffer *__prev; /* Chaining of cleanup functions. */ 176 }; 177 178 /* Cancellation */ 179 enum { 180 PTHREAD_CANCEL_ENABLE, 181 #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE 182 PTHREAD_CANCEL_DISABLE 183 #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE 184 }; 185 enum { 186 PTHREAD_CANCEL_DEFERRED, 187 #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED 188 PTHREAD_CANCEL_ASYNCHRONOUS 189 #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS 190 }; 191 #define PTHREAD_CANCELED ((void *) -1) 192 193 /* Single execution handling. */ 194 #define PTHREAD_ONCE_INIT 0 195 196 #ifdef __USE_XOPEN2K 197 /* Value returned by 'pthread_barrier_wait' for one of the threads after 198 the required number of threads have called this function. 199 -1 is distinct from 0 and all errno constants */ 200 # define PTHREAD_BARRIER_SERIAL_THREAD -1 201 #endif 202 203 __BEGIN_DECLS 204 /* Create a new thread, starting with execution of START-ROUTINE 205 getting passed ARG. Creation attributed come from ATTR. The new 206 handle is stored in *NEWTHREAD. */ 207 extern int pthread_create(pthread_t * __restrict __newthread, const pthread_attr_t * __restrict __attr, void *(*__start_routine) (void *), void *__restrict __arg) 208 __THROWNL __nonnull((1, 3)); 209 210 /* Terminate calling thread. 211 212 The registered cleanup handlers are called via exception handling 213 so we cannot mark this function with __THROW.*/ 214 extern void pthread_exit(void *__retval) __attribute__ ((__noreturn__)); 215 216 /* Make calling thread wait for termination of the thread TH. The 217 exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN 218 is not NULL. 219 220 This function is a cancellation point and therefore not marked with 221 __THROW. */ 222 extern int pthread_join(pthread_t __th, void **__thread_return); 223 224 #ifdef __USE_GNU 225 /* Check whether thread TH has terminated. If yes return the status of 226 the thread in *THREAD_RETURN, if THREAD_RETURN is not NULL. */ 227 extern int pthread_tryjoin_np(pthread_t __th, void **__thread_return) __THROW; 228 229 /* Make calling thread wait for termination of the thread TH, but only 230 until TIMEOUT. The exit status of the thread is stored in 231 *THREAD_RETURN, if THREAD_RETURN is not NULL. 232 233 This function is a cancellation point and therefore not marked with 234 __THROW. */ 235 extern int pthread_timedjoin_np(pthread_t __th, void **__thread_return, const struct timespec *__abstime); 236 #endif 237 238 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN. 239 The resources of TH will therefore be freed immediately when it 240 terminates, instead of waiting for another thread to perform PTHREAD_JOIN 241 on it. */ 242 extern int pthread_detach(pthread_t __th) __THROW; 243 244 /* Obtain the identifier of the current thread. */ 245 extern pthread_t pthread_self(void) 246 __THROW __attribute__ ((__const__)); 247 248 /* Compare two thread identifiers. */ 249 extern int pthread_equal(pthread_t __thread1, pthread_t __thread2) 250 __THROW __attribute__ ((__const__)); 251 252 /* Thread attribute handling. */ 253 254 /* Initialize thread attribute *ATTR with default attributes 255 (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER, 256 no user-provided stack). */ 257 extern int pthread_attr_init(pthread_attr_t * __attr) 258 __THROW __nonnull((1)); 259 260 /* Destroy thread attribute *ATTR. */ 261 extern int pthread_attr_destroy(pthread_attr_t * __attr) 262 __THROW __nonnull((1)); 263 264 /* Get detach state attribute. */ 265 extern int pthread_attr_getdetachstate(const pthread_attr_t * __attr, int *__detachstate) 266 __THROW __nonnull((1, 2)); 267 268 /* Set detach state attribute. */ 269 extern int pthread_attr_setdetachstate(pthread_attr_t * __attr, int __detachstate) 270 __THROW __nonnull((1)); 271 272 /* Get the size of the guard area created for stack overflow protection. */ 273 extern int pthread_attr_getguardsize(const pthread_attr_t * __attr, size_t * __guardsize) 274 __THROW __nonnull((1, 2)); 275 276 /* Set the size of the guard area created for stack overflow protection. */ 277 extern int pthread_attr_setguardsize(pthread_attr_t * __attr, size_t __guardsize) 278 __THROW __nonnull((1)); 279 280 /* Return in *PARAM the scheduling parameters of *ATTR. */ 281 extern int pthread_attr_getschedparam(const pthread_attr_t * __restrict __attr, struct sched_param *__restrict __param) 282 __THROW __nonnull((1, 2)); 283 284 /* Set scheduling parameters (priority, etc) in *ATTR according to PARAM. */ 285 extern int pthread_attr_setschedparam(pthread_attr_t * __restrict __attr, const struct sched_param *__restrict __param) 286 __THROW __nonnull((1, 2)); 287 288 /* Return in *POLICY the scheduling policy of *ATTR. */ 289 extern int pthread_attr_getschedpolicy(const pthread_attr_t * __restrict __attr, int *__restrict __policy) 290 __THROW __nonnull((1, 2)); 291 292 /* Set scheduling policy in *ATTR according to POLICY. */ 293 extern int pthread_attr_setschedpolicy(pthread_attr_t * __attr, int __policy) 294 __THROW __nonnull((1)); 295 296 /* Return in *INHERIT the scheduling inheritance mode of *ATTR. */ 297 extern int pthread_attr_getinheritsched(const pthread_attr_t * __restrict __attr, int *__restrict __inherit) 298 __THROW __nonnull((1, 2)); 299 300 /* Set scheduling inheritance mode in *ATTR according to INHERIT. */ 301 extern int pthread_attr_setinheritsched(pthread_attr_t * __attr, int __inherit) 302 __THROW __nonnull((1)); 303 304 /* Return in *SCOPE the scheduling contention scope of *ATTR. */ 305 extern int pthread_attr_getscope(const pthread_attr_t * __restrict __attr, int *__restrict __scope) 306 __THROW __nonnull((1, 2)); 307 308 /* Set scheduling contention scope in *ATTR according to SCOPE. */ 309 extern int pthread_attr_setscope(pthread_attr_t * __attr, int __scope) 310 __THROW __nonnull((1)); 311 312 /* Return the previously set address for the stack. */ 313 extern int pthread_attr_getstackaddr(const pthread_attr_t * __restrict __attr, void **__restrict __stackaddr) 314 __THROW __nonnull((1, 2)) __attribute_deprecated__; 315 316 /* Set the starting address of the stack of the thread to be created. 317 Depending on whether the stack grows up or down the value must either 318 be higher or lower than all the address in the memory block. The 319 minimal size of the block must be PTHREAD_STACK_MIN. */ 320 extern int pthread_attr_setstackaddr(pthread_attr_t * __attr, void *__stackaddr) 321 __THROW __nonnull((1)) __attribute_deprecated__; 322 323 /* Return the currently used minimal stack size. */ 324 extern int pthread_attr_getstacksize(const pthread_attr_t * __restrict __attr, size_t * __restrict __stacksize) 325 __THROW __nonnull((1, 2)); 326 327 /* Add information about the minimum stack size needed for the thread 328 to be started. This size must never be less than PTHREAD_STACK_MIN 329 and must also not exceed the system limits. */ 330 extern int pthread_attr_setstacksize(pthread_attr_t * __attr, size_t __stacksize) 331 __THROW __nonnull((1)); 332 333 #ifdef __USE_XOPEN2K 334 /* Return the previously set address for the stack. */ 335 extern int pthread_attr_getstack(const pthread_attr_t * __restrict __attr, void **__restrict __stackaddr, size_t * __restrict __stacksize) 336 __THROW __nonnull((1, 2, 3)); 337 338 /* The following two interfaces are intended to replace the last two. They 339 require setting the address as well as the size since only setting the 340 address will make the implementation on some architectures impossible. */ 341 extern int pthread_attr_setstack(pthread_attr_t * __attr, void *__stackaddr, size_t __stacksize) 342 __THROW __nonnull((1)); 343 #endif 344 345 #ifdef __USE_GNU 346 /* Thread created with attribute ATTR will be limited to run only on 347 the processors represented in CPUSET. */ 348 extern int pthread_attr_setaffinity_np(pthread_attr_t * __attr, size_t __cpusetsize, const cpu_set_t * __cpuset) 349 __THROW __nonnull((1, 3)); 350 351 /* Get bit set in CPUSET representing the processors threads created with 352 ATTR can run on. */ 353 extern int pthread_attr_getaffinity_np(const pthread_attr_t * __attr, size_t __cpusetsize, cpu_set_t * __cpuset) 354 __THROW __nonnull((1, 3)); 355 356 /* Get the default attributes used by pthread_create in this process. */ 357 extern int pthread_getattr_default_np(pthread_attr_t * __attr) 358 __THROW __nonnull((1)); 359 360 /* Set the default attributes to be used by pthread_create in this 361 process. */ 362 extern int pthread_setattr_default_np(const pthread_attr_t * __attr) 363 __THROW __nonnull((1)); 364 365 /* Initialize thread attribute *ATTR with attributes corresponding to the 366 already running thread TH. It shall be called on uninitialized ATTR 367 and destroyed with pthread_attr_destroy when no longer needed. */ 368 extern int pthread_getattr_np(pthread_t __th, pthread_attr_t * __attr) 369 __THROW __nonnull((2)); 370 #endif 371 372 /* Functions for scheduling control. */ 373 374 /* Set the scheduling parameters for TARGET_THREAD according to POLICY 375 and *PARAM. */ 376 extern int pthread_setschedparam(pthread_t __target_thread, int __policy, const struct sched_param *__param) 377 __THROW __nonnull((3)); 378 379 /* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */ 380 extern int pthread_getschedparam(pthread_t __target_thread, int *__restrict __policy, struct sched_param *__restrict __param) 381 __THROW __nonnull((2, 3)); 382 383 /* Set the scheduling priority for TARGET_THREAD. */ 384 extern int pthread_setschedprio(pthread_t __target_thread, int __prio) __THROW; 385 386 #ifdef __USE_GNU 387 /* Get thread name visible in the kernel and its interfaces. */ 388 extern int pthread_getname_np(pthread_t __target_thread, char *__buf, size_t __buflen) 389 __THROW __nonnull((2)); 390 391 /* Set thread name visible in the kernel and its interfaces. */ 392 extern int pthread_setname_np(pthread_t __target_thread, const char *__name) 393 __THROW __nonnull((2)); 394 #endif 395 396 #ifdef __USE_UNIX98 397 /* Determine level of concurrency. */ 398 extern int pthread_getconcurrency(void) __THROW; 399 400 /* Set new concurrency level to LEVEL. */ 401 extern int pthread_setconcurrency(int __level) __THROW; 402 #endif 403 404 #ifdef __USE_GNU 405 /* Yield the processor to another thread or process. 406 This function is similar to the POSIX `sched_yield' function but 407 might be differently implemented in the case of a m-on-n thread 408 implementation. */ 409 extern int pthread_yield(void) __THROW; 410 411 /* Limit specified thread TH to run only on the processors represented 412 in CPUSET. */ 413 extern int pthread_setaffinity_np(pthread_t __th, size_t __cpusetsize, const cpu_set_t * __cpuset) 414 __THROW __nonnull((3)); 415 416 /* Get bit set in CPUSET representing the processors TH can run on. */ 417 extern int pthread_getaffinity_np(pthread_t __th, size_t __cpusetsize, cpu_set_t * __cpuset) 418 __THROW __nonnull((3)); 419 #endif 420 421 /* Functions for handling initialization. */ 422 423 /* Guarantee that the initialization function INIT_ROUTINE will be called 424 only once, even if pthread_once is executed several times with the 425 same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or 426 extern variable initialized to PTHREAD_ONCE_INIT. 427 428 The initialization functions might throw exception which is why 429 this function is not marked with __THROW. */ 430 extern int pthread_once(pthread_once_t * __once_control, void (*__init_routine) (void)) __nonnull((1, 2)); 431 432 /* Functions for handling cancellation. 433 434 Note that these functions are explicitly not marked to not throw an 435 exception in C++ code. If cancellation is implemented by unwinding 436 this is necessary to have the compiler generate the unwind information. */ 437 438 /* Set cancelability state of current thread to STATE, returning old 439 state in *OLDSTATE if OLDSTATE is not NULL. */ 440 extern int pthread_setcancelstate(int __state, int *__oldstate); 441 442 /* Set cancellation state of current thread to TYPE, returning the old 443 type in *OLDTYPE if OLDTYPE is not NULL. */ 444 extern int pthread_setcanceltype(int __type, int *__oldtype); 445 446 /* Cancel THREAD immediately or at the next possibility. */ 447 extern int pthread_cancel(pthread_t __th); 448 449 /* Test for pending cancellation for the current thread and terminate 450 the thread as per pthread_exit(PTHREAD_CANCELED) if it has been 451 cancelled. */ 452 extern void pthread_testcancel(void); 453 454 /* Cancellation handling with integration into exception handling. */ 455 456 typedef struct { 457 struct { 458 __jmp_buf __cancel_jmp_buf; 459 int __mask_was_saved; 460 } __cancel_jmp_buf[1]; 461 void *__pad[4]; 462 } __pthread_unwind_buf_t __attribute__ ((__aligned__)); 463 464 /* No special attributes by default. */ 465 #ifndef __cleanup_fct_attribute 466 # define __cleanup_fct_attribute 467 #endif 468 469 /* Structure to hold the cleanup handler information. */ 470 struct __pthread_cleanup_frame { 471 void (*__cancel_routine) (void *); 472 void *__cancel_arg; 473 int __do_it; 474 int __cancel_type; 475 }; 476 477 #if defined __GNUC__ && defined __EXCEPTIONS 478 # ifdef __cplusplus 479 /* Class to handle cancellation handler invocation. */ 480 class __pthread_cleanup_class { 481 void (*__cancel_routine) (void *); 482 void *__cancel_arg; 483 int __do_it; 484 int __cancel_type; 485 486 public: 487 __pthread_cleanup_class(void (*__fct) (void *), void *__arg) 488 :__cancel_routine(__fct), __cancel_arg(__arg), __do_it(1) 489 { 490 } ~__pthread_cleanup_class() { 491 if (__do_it) 492 __cancel_routine(__cancel_arg); 493 } 494 void __setdoit(int __newval) { 495 __do_it = __newval; 496 } 497 void __defer() { 498 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &__cancel_type); 499 } 500 void __restore() const { 501 pthread_setcanceltype(__cancel_type, 0); 502 }}; 503 504 /* Install a cleanup handler: ROUTINE will be called with arguments ARG 505 when the thread is canceled or calls pthread_exit. ROUTINE will also 506 be called with arguments ARG when the matching pthread_cleanup_pop 507 is executed with non-zero EXECUTE argument. 508 509 pthread_cleanup_push and pthread_cleanup_pop are macros and must always 510 be used in matching pairs at the same nesting level of braces. */ 511 # define pthread_cleanup_push(routine, arg) \ 512 do { \ 513 __pthread_cleanup_class __clframe (routine, arg) 514 515 /* Remove a cleanup handler installed by the matching pthread_cleanup_push. 516 If EXECUTE is non-zero, the handler function is called. */ 517 # define pthread_cleanup_pop(execute) \ 518 __clframe.__setdoit (execute); \ 519 } while (0) 520 521 # ifdef __USE_GNU 522 /* Install a cleanup handler as pthread_cleanup_push does, but also 523 saves the current cancellation type and sets it to deferred 524 cancellation. */ 525 # define pthread_cleanup_push_defer_np(routine, arg) \ 526 do { \ 527 __pthread_cleanup_class __clframe (routine, arg); \ 528 __clframe.__defer () 529 530 /* Remove a cleanup handler as pthread_cleanup_pop does, but also 531 restores the cancellation type that was in effect when the matching 532 pthread_cleanup_push_defer was called. */ 533 # define pthread_cleanup_pop_restore_np(execute) \ 534 __clframe.__restore (); \ 535 __clframe.__setdoit (execute); \ 536 } while (0) 537 # endif 538 # else 539 /* Function called to call the cleanup handler. As an extern inline 540 function the compiler is free to decide inlining the change when 541 needed or fall back on the copy which must exist somewhere 542 else. */ 543 __extern_inline void __pthread_cleanup_routine(struct __pthread_cleanup_frame *__frame) 544 { 545 if (__frame->__do_it) 546 __frame->__cancel_routine(__frame->__cancel_arg); 547 } 548 549 /* Install a cleanup handler: ROUTINE will be called with arguments ARG 550 when the thread is canceled or calls pthread_exit. ROUTINE will also 551 be called with arguments ARG when the matching pthread_cleanup_pop 552 is executed with non-zero EXECUTE argument. 553 554 pthread_cleanup_push and pthread_cleanup_pop are macros and must always 555 be used in matching pairs at the same nesting level of braces. */ 556 # define pthread_cleanup_push(routine, arg) \ 557 do { \ 558 struct __pthread_cleanup_frame __clframe \ 559 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ 560 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ 561 .__do_it = 1 }; 562 563 /* Remove a cleanup handler installed by the matching pthread_cleanup_push. 564 If EXECUTE is non-zero, the handler function is called. */ 565 # define pthread_cleanup_pop(execute) \ 566 __clframe.__do_it = (execute); \ 567 } while (0) 568 569 # ifdef __USE_GNU 570 /* Install a cleanup handler as pthread_cleanup_push does, but also 571 saves the current cancellation type and sets it to deferred 572 cancellation. */ 573 # define pthread_cleanup_push_defer_np(routine, arg) \ 574 do { \ 575 struct __pthread_cleanup_frame __clframe \ 576 __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ 577 = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ 578 .__do_it = 1 }; \ 579 (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \ 580 &__clframe.__cancel_type) 581 582 /* Remove a cleanup handler as pthread_cleanup_pop does, but also 583 restores the cancellation type that was in effect when the matching 584 pthread_cleanup_push_defer was called. */ 585 # define pthread_cleanup_pop_restore_np(execute) \ 586 (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \ 587 __clframe.__do_it = (execute); \ 588 } while (0) 589 # endif 590 # endif 591 #else 592 /* Install a cleanup handler: ROUTINE will be called with arguments ARG 593 when the thread is canceled or calls pthread_exit. ROUTINE will also 594 be called with arguments ARG when the matching pthread_cleanup_pop 595 is executed with non-zero EXECUTE argument. 596 597 pthread_cleanup_push and pthread_cleanup_pop are macros and must always 598 be used in matching pairs at the same nesting level of braces. */ 599 # define pthread_cleanup_push(routine, arg) \ 600 do { \ 601 __pthread_unwind_buf_t __cancel_buf; \ 602 void (*__cancel_routine) (void *) = (routine); \ 603 void *__cancel_arg = (arg); \ 604 int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ 605 __cancel_buf.__cancel_jmp_buf, 0); \ 606 if (__glibc_unlikely (__not_first_call)) \ 607 { \ 608 __cancel_routine (__cancel_arg); \ 609 __pthread_unwind_next (&__cancel_buf); \ 610 /* NOTREACHED */ \ 611 } \ 612 \ 613 __pthread_register_cancel (&__cancel_buf); \ 614 do { 615 extern void __pthread_register_cancel(__pthread_unwind_buf_t * __buf) __cleanup_fct_attribute; 616 617 /* Remove a cleanup handler installed by the matching pthread_cleanup_push. 618 If EXECUTE is non-zero, the handler function is called. */ 619 # define pthread_cleanup_pop(execute) \ 620 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ 621 } while (0); \ 622 __pthread_unregister_cancel (&__cancel_buf); \ 623 if (execute) \ 624 __cancel_routine (__cancel_arg); \ 625 } while (0) 626 extern void __pthread_unregister_cancel(__pthread_unwind_buf_t * __buf) __cleanup_fct_attribute; 627 628 # ifdef __USE_GNU 629 /* Install a cleanup handler as pthread_cleanup_push does, but also 630 saves the current cancellation type and sets it to deferred 631 cancellation. */ 632 # define pthread_cleanup_push_defer_np(routine, arg) \ 633 do { \ 634 __pthread_unwind_buf_t __cancel_buf; \ 635 void (*__cancel_routine) (void *) = (routine); \ 636 void *__cancel_arg = (arg); \ 637 int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ 638 __cancel_buf.__cancel_jmp_buf, 0); \ 639 if (__glibc_unlikely (__not_first_call)) \ 640 { \ 641 __cancel_routine (__cancel_arg); \ 642 __pthread_unwind_next (&__cancel_buf); \ 643 /* NOTREACHED */ \ 644 } \ 645 \ 646 __pthread_register_cancel_defer (&__cancel_buf); \ 647 do { 648 extern void __pthread_register_cancel_defer(__pthread_unwind_buf_t * __buf) __cleanup_fct_attribute; 649 650 /* Remove a cleanup handler as pthread_cleanup_pop does, but also 651 restores the cancellation type that was in effect when the matching 652 pthread_cleanup_push_defer was called. */ 653 # define pthread_cleanup_pop_restore_np(execute) \ 654 do { } while (0);/* Empty to allow label before pthread_cleanup_pop. */\ 655 } while (0); \ 656 __pthread_unregister_cancel_restore (&__cancel_buf); \ 657 if (execute) \ 658 __cancel_routine (__cancel_arg); \ 659 } while (0) 660 extern void __pthread_unregister_cancel_restore(__pthread_unwind_buf_t * __buf) __cleanup_fct_attribute; 661 # endif 662 663 /* Internal interface to initiate cleanup. */ 664 extern void __pthread_unwind_next(__pthread_unwind_buf_t * __buf) 665 __cleanup_fct_attribute __attribute__ ((__noreturn__)) 666 # ifndef SHARED 667 __attribute__ ((__weak__)) 668 # endif 669 ; 670 #endif 671 672 /* Function used in the macros. */ 673 struct __jmp_buf_tag; 674 extern int __sigsetjmp(struct __jmp_buf_tag *__env, int __savemask) __THROWNL; 675 676 /* Mutex handling. */ 677 678 /* Initialize a mutex. */ 679 extern int pthread_mutex_init(pthread_mutex_t * __mutex, const pthread_mutexattr_t * __mutexattr) 680 __THROW __nonnull((1)); 681 682 /* Destroy a mutex. */ 683 extern int pthread_mutex_destroy(pthread_mutex_t * __mutex) 684 __THROW __nonnull((1)); 685 686 /* Try locking a mutex. */ 687 extern int pthread_mutex_trylock(pthread_mutex_t * __mutex) 688 __THROWNL __nonnull((1)); 689 690 /* Lock a mutex. */ 691 extern int pthread_mutex_lock(pthread_mutex_t * __mutex) 692 __THROWNL __nonnull((1)); 693 694 #ifdef __USE_XOPEN2K 695 /* Wait until lock becomes available, or specified time passes. */ 696 extern int pthread_mutex_timedlock(pthread_mutex_t * __restrict __mutex, const struct timespec *__restrict __abstime) 697 __THROWNL __nonnull((1, 2)); 698 #endif 699 700 /* Unlock a mutex. */ 701 extern int pthread_mutex_unlock(pthread_mutex_t * __mutex) 702 __THROWNL __nonnull((1)); 703 704 /* Get the priority ceiling of MUTEX. */ 705 extern int pthread_mutex_getprioceiling(const pthread_mutex_t * __restrict __mutex, int *__restrict __prioceiling) 706 __THROW __nonnull((1, 2)); 707 708 /* Set the priority ceiling of MUTEX to PRIOCEILING, return old 709 priority ceiling value in *OLD_CEILING. */ 710 extern int pthread_mutex_setprioceiling(pthread_mutex_t * __restrict __mutex, int __prioceiling, int *__restrict __old_ceiling) 711 __THROW __nonnull((1, 3)); 712 713 #ifdef __USE_XOPEN2K8 714 /* Declare the state protected by MUTEX as consistent. */ 715 extern int pthread_mutex_consistent(pthread_mutex_t * __mutex) 716 __THROW __nonnull((1)); 717 # ifdef __USE_GNU 718 extern int pthread_mutex_consistent_np(pthread_mutex_t * __mutex) 719 __THROW __nonnull((1)); 720 # endif 721 #endif 722 723 /* Functions for handling mutex attributes. */ 724 725 /* Initialize mutex attribute object ATTR with default attributes 726 (kind is PTHREAD_MUTEX_TIMED_NP). */ 727 extern int pthread_mutexattr_init(pthread_mutexattr_t * __attr) 728 __THROW __nonnull((1)); 729 730 /* Destroy mutex attribute object ATTR. */ 731 extern int pthread_mutexattr_destroy(pthread_mutexattr_t * __attr) 732 __THROW __nonnull((1)); 733 734 /* Get the process-shared flag of the mutex attribute ATTR. */ 735 extern int pthread_mutexattr_getpshared(const pthread_mutexattr_t * __restrict __attr, int *__restrict __pshared) 736 __THROW __nonnull((1, 2)); 737 738 /* Set the process-shared flag of the mutex attribute ATTR. */ 739 extern int pthread_mutexattr_setpshared(pthread_mutexattr_t * __attr, int __pshared) 740 __THROW __nonnull((1)); 741 742 #if defined __USE_UNIX98 || defined __USE_XOPEN2K8 743 /* Return in *KIND the mutex kind attribute in *ATTR. */ 744 extern int pthread_mutexattr_gettype(const pthread_mutexattr_t * __restrict __attr, int *__restrict __kind) 745 __THROW __nonnull((1, 2)); 746 747 /* Set the mutex kind attribute in *ATTR to KIND (either PTHREAD_MUTEX_NORMAL, 748 PTHREAD_MUTEX_RECURSIVE, PTHREAD_MUTEX_ERRORCHECK, or 749 PTHREAD_MUTEX_DEFAULT). */ 750 extern int pthread_mutexattr_settype(pthread_mutexattr_t * __attr, int __kind) 751 __THROW __nonnull((1)); 752 #endif 753 754 /* Return in *PROTOCOL the mutex protocol attribute in *ATTR. */ 755 extern int pthread_mutexattr_getprotocol(const pthread_mutexattr_t * __restrict __attr, int *__restrict __protocol) 756 __THROW __nonnull((1, 2)); 757 758 /* Set the mutex protocol attribute in *ATTR to PROTOCOL (either 759 PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT). */ 760 extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t * __attr, int __protocol) 761 __THROW __nonnull((1)); 762 763 /* Return in *PRIOCEILING the mutex prioceiling attribute in *ATTR. */ 764 extern int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t * __restrict __attr, int *__restrict __prioceiling) 765 __THROW __nonnull((1, 2)); 766 767 /* Set the mutex prioceiling attribute in *ATTR to PRIOCEILING. */ 768 extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t * __attr, int __prioceiling) 769 __THROW __nonnull((1)); 770 771 #ifdef __USE_XOPEN2K 772 /* Get the robustness flag of the mutex attribute ATTR. */ 773 extern int pthread_mutexattr_getrobust(const pthread_mutexattr_t * __attr, int *__robustness) 774 __THROW __nonnull((1, 2)); 775 # ifdef __USE_GNU 776 extern int pthread_mutexattr_getrobust_np(const pthread_mutexattr_t * __attr, int *__robustness) 777 __THROW __nonnull((1, 2)); 778 # endif 779 780 /* Set the robustness flag of the mutex attribute ATTR. */ 781 extern int pthread_mutexattr_setrobust(pthread_mutexattr_t * __attr, int __robustness) 782 __THROW __nonnull((1)); 783 # ifdef __USE_GNU 784 extern int pthread_mutexattr_setrobust_np(pthread_mutexattr_t * __attr, int __robustness) 785 __THROW __nonnull((1)); 786 # endif 787 #endif 788 789 #if defined __USE_UNIX98 || defined __USE_XOPEN2K 790 /* Functions for handling read-write locks. */ 791 792 /* Initialize read-write lock RWLOCK using attributes ATTR, or use 793 the default values if later is NULL. */ 794 extern int pthread_rwlock_init(pthread_rwlock_t * __restrict __rwlock, const pthread_rwlockattr_t * __restrict __attr) 795 __THROW __nonnull((1)); 796 797 /* Destroy read-write lock RWLOCK. */ 798 extern int pthread_rwlock_destroy(pthread_rwlock_t * __rwlock) 799 __THROW __nonnull((1)); 800 801 /* Acquire read lock for RWLOCK. */ 802 extern int pthread_rwlock_rdlock(pthread_rwlock_t * __rwlock) 803 __THROWNL __nonnull((1)); 804 805 /* Try to acquire read lock for RWLOCK. */ 806 extern int pthread_rwlock_tryrdlock(pthread_rwlock_t * __rwlock) 807 __THROWNL __nonnull((1)); 808 809 # ifdef __USE_XOPEN2K 810 /* Try to acquire read lock for RWLOCK or return after specfied time. */ 811 extern int pthread_rwlock_timedrdlock(pthread_rwlock_t * __restrict __rwlock, const struct timespec *__restrict __abstime) 812 __THROWNL __nonnull((1, 2)); 813 # endif 814 815 /* Acquire write lock for RWLOCK. */ 816 extern int pthread_rwlock_wrlock(pthread_rwlock_t * __rwlock) 817 __THROWNL __nonnull((1)); 818 819 /* Try to acquire write lock for RWLOCK. */ 820 extern int pthread_rwlock_trywrlock(pthread_rwlock_t * __rwlock) 821 __THROWNL __nonnull((1)); 822 823 # ifdef __USE_XOPEN2K 824 /* Try to acquire write lock for RWLOCK or return after specfied time. */ 825 extern int pthread_rwlock_timedwrlock(pthread_rwlock_t * __restrict __rwlock, const struct timespec *__restrict __abstime) 826 __THROWNL __nonnull((1, 2)); 827 # endif 828 829 /* Unlock RWLOCK. */ 830 extern int pthread_rwlock_unlock(pthread_rwlock_t * __rwlock) 831 __THROWNL __nonnull((1)); 832 833 /* Functions for handling read-write lock attributes. */ 834 835 /* Initialize attribute object ATTR with default values. */ 836 extern int pthread_rwlockattr_init(pthread_rwlockattr_t * __attr) 837 __THROW __nonnull((1)); 838 839 /* Destroy attribute object ATTR. */ 840 extern int pthread_rwlockattr_destroy(pthread_rwlockattr_t * __attr) 841 __THROW __nonnull((1)); 842 843 /* Return current setting of process-shared attribute of ATTR in PSHARED. */ 844 extern int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t * __restrict __attr, int *__restrict __pshared) 845 __THROW __nonnull((1, 2)); 846 847 /* Set process-shared attribute of ATTR to PSHARED. */ 848 extern int pthread_rwlockattr_setpshared(pthread_rwlockattr_t * __attr, int __pshared) 849 __THROW __nonnull((1)); 850 851 /* Return current setting of reader/writer preference. */ 852 extern int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t * __restrict __attr, int *__restrict __pref) 853 __THROW __nonnull((1, 2)); 854 855 /* Set reader/write preference. */ 856 extern int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t * __attr, int __pref) 857 __THROW __nonnull((1)); 858 #endif 859 860 /* Functions for handling conditional variables. */ 861 862 /* Initialize condition variable COND using attributes ATTR, or use 863 the default values if later is NULL. */ 864 extern int pthread_cond_init(pthread_cond_t * __restrict __cond, const pthread_condattr_t * __restrict __cond_attr) 865 __THROW __nonnull((1)); 866 867 /* Destroy condition variable COND. */ 868 extern int pthread_cond_destroy(pthread_cond_t * __cond) 869 __THROW __nonnull((1)); 870 871 /* Wake up one thread waiting for condition variable COND. */ 872 extern int pthread_cond_signal(pthread_cond_t * __cond) 873 __THROWNL __nonnull((1)); 874 875 /* Wake up all threads waiting for condition variables COND. */ 876 extern int pthread_cond_broadcast(pthread_cond_t * __cond) 877 __THROWNL __nonnull((1)); 878 879 /* Wait for condition variable COND to be signaled or broadcast. 880 MUTEX is assumed to be locked before. 881 882 This function is a cancellation point and therefore not marked with 883 __THROW. */ 884 extern int pthread_cond_wait(pthread_cond_t * __restrict __cond, pthread_mutex_t * __restrict __mutex) __nonnull((1, 2)); 885 886 /* Wait for condition variable COND to be signaled or broadcast until 887 ABSTIME. MUTEX is assumed to be locked before. ABSTIME is an 888 absolute time specification; zero is the beginning of the epoch 889 (00:00:00 GMT, January 1, 1970). 890 891 This function is a cancellation point and therefore not marked with 892 __THROW. */ 893 extern int pthread_cond_timedwait(pthread_cond_t * __restrict __cond, pthread_mutex_t * __restrict __mutex, const struct timespec *__restrict __abstime) __nonnull((1, 2, 3)); 894 895 /* Functions for handling condition variable attributes. */ 896 897 /* Initialize condition variable attribute ATTR. */ 898 extern int pthread_condattr_init(pthread_condattr_t * __attr) 899 __THROW __nonnull((1)); 900 901 /* Destroy condition variable attribute ATTR. */ 902 extern int pthread_condattr_destroy(pthread_condattr_t * __attr) 903 __THROW __nonnull((1)); 904 905 /* Get the process-shared flag of the condition variable attribute ATTR. */ 906 extern int pthread_condattr_getpshared(const pthread_condattr_t * __restrict __attr, int *__restrict __pshared) 907 __THROW __nonnull((1, 2)); 908 909 /* Set the process-shared flag of the condition variable attribute ATTR. */ 910 extern int pthread_condattr_setpshared(pthread_condattr_t * __attr, int __pshared) 911 __THROW __nonnull((1)); 912 913 #ifdef __USE_XOPEN2K 914 /* Get the clock selected for the condition variable attribute ATTR. */ 915 extern int pthread_condattr_getclock(const pthread_condattr_t * __restrict __attr, __clockid_t * __restrict __clock_id) 916 __THROW __nonnull((1, 2)); 917 918 /* Set the clock selected for the condition variable attribute ATTR. */ 919 extern int pthread_condattr_setclock(pthread_condattr_t * __attr, __clockid_t __clock_id) 920 __THROW __nonnull((1)); 921 #endif 922 923 #ifdef __USE_XOPEN2K 924 /* Functions to handle spinlocks. */ 925 926 /* Initialize the spinlock LOCK. If PSHARED is nonzero the spinlock can 927 be shared between different processes. */ 928 extern int pthread_spin_init(pthread_spinlock_t * __lock, int __pshared) 929 __THROW __nonnull((1)); 930 931 /* Destroy the spinlock LOCK. */ 932 extern int pthread_spin_destroy(pthread_spinlock_t * __lock) 933 __THROW __nonnull((1)); 934 935 /* Wait until spinlock LOCK is retrieved. */ 936 extern int pthread_spin_lock(pthread_spinlock_t * __lock) 937 __THROWNL __nonnull((1)); 938 939 /* Try to lock spinlock LOCK. */ 940 extern int pthread_spin_trylock(pthread_spinlock_t * __lock) 941 __THROWNL __nonnull((1)); 942 943 /* Release spinlock LOCK. */ 944 extern int pthread_spin_unlock(pthread_spinlock_t * __lock) 945 __THROWNL __nonnull((1)); 946 947 /* Functions to handle barriers. */ 948 949 /* Initialize BARRIER with the attributes in ATTR. The barrier is 950 opened when COUNT waiters arrived. */ 951 extern int pthread_barrier_init(pthread_barrier_t * __restrict __barrier, const pthread_barrierattr_t * __restrict __attr, unsigned int __count) 952 __THROW __nonnull((1)); 953 954 /* Destroy a previously dynamically initialized barrier BARRIER. */ 955 extern int pthread_barrier_destroy(pthread_barrier_t * __barrier) 956 __THROW __nonnull((1)); 957 958 /* Wait on barrier BARRIER. */ 959 extern int pthread_barrier_wait(pthread_barrier_t * __barrier) 960 __THROWNL __nonnull((1)); 961 962 /* Initialize barrier attribute ATTR. */ 963 extern int pthread_barrierattr_init(pthread_barrierattr_t * __attr) 964 __THROW __nonnull((1)); 965 966 /* Destroy previously dynamically initialized barrier attribute ATTR. */ 967 extern int pthread_barrierattr_destroy(pthread_barrierattr_t * __attr) 968 __THROW __nonnull((1)); 969 970 /* Get the process-shared flag of the barrier attribute ATTR. */ 971 extern int pthread_barrierattr_getpshared(const pthread_barrierattr_t * __restrict __attr, int *__restrict __pshared) 972 __THROW __nonnull((1, 2)); 973 974 /* Set the process-shared flag of the barrier attribute ATTR. */ 975 extern int pthread_barrierattr_setpshared(pthread_barrierattr_t * __attr, int __pshared) 976 __THROW __nonnull((1)); 977 #endif 978 979 /* Functions for handling thread-specific data. */ 980 981 /* Create a key value identifying a location in the thread-specific 982 data area. Each thread maintains a distinct thread-specific data 983 area. DESTR_FUNCTION, if non-NULL, is called with the value 984 associated to that key when the key is destroyed. 985 DESTR_FUNCTION is not called if the value associated is NULL when 986 the key is destroyed. */ 987 extern int pthread_key_create(pthread_key_t * __key, void (*__destr_function) (void *)) 988 __THROW __nonnull((1)); 989 990 /* Destroy KEY. */ 991 extern int pthread_key_delete(pthread_key_t __key) __THROW; 992 993 /* Return current value of the thread-specific data slot identified by KEY. */ 994 extern void *pthread_getspecific(pthread_key_t __key) __THROW; 995 996 /* Store POINTER in the thread-specific data slot identified by KEY. */ 997 extern int pthread_setspecific(pthread_key_t __key, const void *__pointer) __THROW; 998 999 #ifdef __USE_XOPEN2K 1000 /* Get ID of CPU-time clock for thread THREAD_ID. */ 1001 extern int pthread_getcpuclockid(pthread_t __thread_id, __clockid_t * __clock_id) 1002 __THROW __nonnull((2)); 1003 #endif 1004 1005 /* Install handlers to be called when a new process is created with FORK. 1006 The PREPARE handler is called in the parent process just before performing 1007 FORK. The PARENT handler is called in the parent process just after FORK. 1008 The CHILD handler is called in the child process. Each of the three 1009 handlers can be NULL, meaning that no handler needs to be called at that 1010 point. 1011 PTHREAD_ATFORK can be called several times, in which case the PREPARE 1012 handlers are called in LIFO order (last added with PTHREAD_ATFORK, 1013 first called before FORK), and the PARENT and CHILD handlers are called 1014 in FIFO (first added, first called). */ 1015 1016 extern int pthread_atfork(void (*__prepare) (void), void (*__parent) (void), void (*__child) (void)) __THROW; 1017 1018 #ifdef __USE_EXTERN_INLINES 1019 /* Optimizations. */ 1020 __extern_inline int __NTH(pthread_equal(pthread_t __thread1, pthread_t __thread2)) 1021 { 1022 return __thread1 == __thread2; 1023 } 1024 #endif 1025 1026 __END_DECLS 1027 #endif /* pthread.h */