readv2: Note preadv2(..., RWF_NOWAIT) bug in BUGS section
[man-pages.git] / man7 / pthreads.7
blob6f4f6e763cb1fc7e777c92d204d9c7fbe053ad13
1 .\" Copyright (c) 2005 by Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PTHREADS 7  2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 pthreads \- POSIX threads
28 .SH DESCRIPTION
29 POSIX.1 specifies a set of interfaces (functions, header files) for
30 threaded programming commonly known as POSIX threads, or Pthreads.
31 A single process can contain multiple threads,
32 all of which are executing the same program.
33 These threads share the same global memory (data and heap segments),
34 but each thread has its own stack (automatic variables).
35 .PP
36 POSIX.1 also requires that threads share a range of other attributes
37 (i.e., these attributes are process-wide rather than per-thread):
38 .IP \- 3
39 process ID
40 .IP \- 3
41 parent process ID
42 .IP \- 3
43 process group ID and session ID
44 .IP \- 3
45 controlling terminal
46 .IP \- 3
47 user and group IDs
48 .IP \- 3
49 open file descriptors
50 .IP \- 3
51 record locks (see
52 .BR fcntl (2))
53 .IP \- 3
54 signal dispositions
55 .IP \- 3
56 file mode creation mask
57 .RB ( umask (2))
58 .IP \- 3
59 current directory
60 .RB ( chdir (2))
61 and
62 root directory
63 .RB ( chroot (2))
64 .IP \- 3
65 interval timers
66 .RB ( setitimer (2))
67 and POSIX timers
68 .RB ( timer_create (2))
69 .IP \- 3
70 nice value
71 .RB ( setpriority (2))
72 .IP \- 3
73 resource limits
74 .RB ( setrlimit (2))
75 .IP \- 3
76 measurements of the consumption of CPU time
77 .RB ( times (2))
78 and resources
79 .RB ( getrusage (2))
80 .PP
81 As well as the stack, POSIX.1 specifies that various other
82 attributes are distinct for each thread, including:
83 .IP \- 3
84 thread ID (the
85 .I pthread_t
86 data type)
87 .IP \- 3
88 signal mask
89 .RB ( pthread_sigmask (3))
90 .IP \- 3
91 the
92 .I errno
93 variable
94 .IP \- 3
95 alternate signal stack
96 .RB ( sigaltstack (2))
97 .IP \- 3
98 real-time scheduling policy and priority
99 .RB ( sched (7))
101 The following Linux-specific features are also per-thread:
102 .IP \- 3
103 capabilities (see
104 .BR capabilities (7))
105 .IP \- 3
106 CPU affinity
107 .RB ( sched_setaffinity (2))
108 .SS Pthreads function return values
109 Most pthreads functions return 0 on success, and an error number on failure.
110 The error numbers that can be returned have the same meaning as
111 the error numbers returned in
112 .I errno
113 by conventional system calls and C library functions.
114 Note that the pthreads functions do not set
115 .IR errno .
116 For each of the pthreads functions that can return an error,
117 POSIX.1-2001 specifies that the function can never fail with the error
118 .BR EINTR .
119 .SS Thread IDs
120 Each of the threads in a process has a unique thread identifier
121 (stored in the type
122 .IR pthread_t ).
123 This identifier is returned to the caller of
124 .BR pthread_create (3),
125 and a thread can obtain its own thread identifier using
126 .BR pthread_self (3).
128 Thread IDs are guaranteed to be unique only within a process.
129 (In all pthreads functions that accept a thread ID as an argument,
130 that ID by definition refers to a thread in
131 the same process as the caller.)
133 The system may reuse a thread ID after a terminated thread has been joined,
134 or a detached thread has terminated.
135 POSIX says: "If an application attempts to use a thread ID whose
136 lifetime has ended, the behavior is undefined."
137 .SS Thread-safe functions
138 A thread-safe function is one that can be safely
139 (i.e., it will deliver the same results regardless of whether it is)
140 called from multiple threads at the same time.
142 POSIX.1-2001 and POSIX.1-2008 require that all functions specified
143 in the standard shall be thread-safe,
144 except for the following functions:
146 .in +4n
148 asctime()
149 basename()
150 catgets()
151 crypt()
152 ctermid() if passed a non-NULL argument
153 ctime()
154 dbm_clearerr()
155 dbm_close()
156 dbm_delete()
157 dbm_error()
158 dbm_fetch()
159 dbm_firstkey()
160 dbm_nextkey()
161 dbm_open()
162 dbm_store()
163 dirname()
164 dlerror()
165 drand48()
166 ecvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
167 encrypt()
168 endgrent()
169 endpwent()
170 endutxent()
171 fcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
172 ftw()
173 gcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
174 getc_unlocked()
175 getchar_unlocked()
176 getdate()
177 getenv()
178 getgrent()
179 getgrgid()
180 getgrnam()
181 gethostbyaddr() [POSIX.1-2001 only (function removed in
182                  POSIX.1-2008)]
183 gethostbyname() [POSIX.1-2001 only (function removed in
184                  POSIX.1-2008)]
185 gethostent()
186 getlogin()
187 getnetbyaddr()
188 getnetbyname()
189 getnetent()
190 getopt()
191 getprotobyname()
192 getprotobynumber()
193 getprotoent()
194 getpwent()
195 getpwnam()
196 getpwuid()
197 getservbyname()
198 getservbyport()
199 getservent()
200 getutxent()
201 getutxid()
202 getutxline()
203 gmtime()
204 hcreate()
205 hdestroy()
206 hsearch()
207 inet_ntoa()
208 l64a()
209 lgamma()
210 lgammaf()
211 lgammal()
212 localeconv()
213 localtime()
214 lrand48()
215 mrand48()
216 nftw()
217 nl_langinfo()
218 ptsname()
219 putc_unlocked()
220 putchar_unlocked()
221 putenv()
222 pututxline()
223 rand()
224 readdir()
225 setenv()
226 setgrent()
227 setkey()
228 setpwent()
229 setutxent()
230 strerror()
231 strsignal() [Added in POSIX.1-2008]
232 strtok()
233 system() [Added in POSIX.1-2008]
234 tmpnam() if passed a non-NULL argument
235 ttyname()
236 unsetenv()
237 wcrtomb() if its final argument is NULL
238 wcsrtombs() if its final argument is NULL
239 wcstombs()
240 wctomb()
243 .SS Async-cancel-safe functions
244 An async-cancel-safe function is one that can be safely called
245 in an application where asynchronous cancelability is enabled (see
246 .BR pthread_setcancelstate (3)).
248 Only the following functions are required to be async-cancel-safe by
249 POSIX.1-2001 and POSIX.1-2008:
251 .in +4n
253 pthread_cancel()
254 pthread_setcancelstate()
255 pthread_setcanceltype()
258 .SS Cancellation points
259 POSIX.1 specifies that certain functions must,
260 and certain other functions may, be cancellation points.
261 If a thread is cancelable, its cancelability type is deferred,
262 and a cancellation request is pending for the thread,
263 then the thread is canceled when it calls a function
264 that is a cancellation point.
266 The following functions are required to be cancellation points by
267 POSIX.1-2001 and/or POSIX.1-2008:
269 .\" FIXME
270 .\" Document the list of all functions that are cancellation points in glibc
271 .in +4n
273 accept()
274 aio_suspend()
275 clock_nanosleep()
276 close()
277 connect()
278 creat()
279 fcntl() F_SETLKW
280 fdatasync()
281 fsync()
282 getmsg()
283 getpmsg()
284 lockf() F_LOCK
285 mq_receive()
286 mq_send()
287 mq_timedreceive()
288 mq_timedsend()
289 msgrcv()
290 msgsnd()
291 msync()
292 nanosleep()
293 open()
294 openat() [Added in POSIX.1-2008]
295 pause()
296 poll()
297 pread()
298 pselect()
299 pthread_cond_timedwait()
300 pthread_cond_wait()
301 pthread_join()
302 pthread_testcancel()
303 putmsg()
304 putpmsg()
305 pwrite()
306 read()
307 readv()
308 recv()
309 recvfrom()
310 recvmsg()
311 select()
312 sem_timedwait()
313 sem_wait()
314 send()
315 sendmsg()
316 sendto()
317 sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)]
318 sigsuspend()
319 sigtimedwait()
320 sigwait()
321 sigwaitinfo()
322 sleep()
323 system()
324 tcdrain()
325 usleep() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
326 wait()
327 waitid()
328 waitpid()
329 write()
330 writev()
334 The following functions may be cancellation points according to
335 POSIX.1-2001 and/or POSIX.1-2008:
337 .in +4n
339 access()
340 asctime()
341 asctime_r()
342 catclose()
343 catgets()
344 catopen()
345 chmod() [Added in POSIX.1-2008]
346 chown() [Added in POSIX.1-2008]
347 closedir()
348 closelog()
349 ctermid()
350 ctime()
351 ctime_r()
352 dbm_close()
353 dbm_delete()
354 dbm_fetch()
355 dbm_nextkey()
356 dbm_open()
357 dbm_store()
358 dlclose()
359 dlopen()
360 dprintf() [Added in POSIX.1-2008]
361 endgrent()
362 endhostent()
363 endnetent()
364 endprotoent()
365 endpwent()
366 endservent()
367 endutxent()
368 faccessat() [Added in POSIX.1-2008]
369 fchmod() [Added in POSIX.1-2008]
370 fchmodat() [Added in POSIX.1-2008]
371 fchown() [Added in POSIX.1-2008]
372 fchownat() [Added in POSIX.1-2008]
373 fclose()
374 fcntl() (for any value of cmd argument)
375 fflush()
376 fgetc()
377 fgetpos()
378 fgets()
379 fgetwc()
380 fgetws()
381 fmtmsg()
382 fopen()
383 fpathconf()
384 fprintf()
385 fputc()
386 fputs()
387 fputwc()
388 fputws()
389 fread()
390 freopen()
391 fscanf()
392 fseek()
393 fseeko()
394 fsetpos()
395 fstat()
396 fstatat() [Added in POSIX.1-2008]
397 ftell()
398 ftello()
399 ftw()
400 futimens() [Added in POSIX.1-2008]
401 fwprintf()
402 fwrite()
403 fwscanf()
404 getaddrinfo()
405 getc()
406 getc_unlocked()
407 getchar()
408 getchar_unlocked()
409 getcwd()
410 getdate()
411 getdelim() [Added in POSIX.1-2008]
412 getgrent()
413 getgrgid()
414 getgrgid_r()
415 getgrnam()
416 getgrnam_r()
417 gethostbyaddr() [POSIX.1-2001 only (function removed in
418                  POSIX.1-2008)]
419 gethostbyname() [POSIX.1-2001 only (function removed in
420                  POSIX.1-2008)]
421 gethostent()
422 gethostid()
423 gethostname()
424 getline() [Added in POSIX.1-2008]
425 getlogin()
426 getlogin_r()
427 getnameinfo()
428 getnetbyaddr()
429 getnetbyname()
430 getnetent()
431 getopt() (if opterr is nonzero)
432 getprotobyname()
433 getprotobynumber()
434 getprotoent()
435 getpwent()
436 getpwnam()
437 getpwnam_r()
438 getpwuid()
439 getpwuid_r()
440 gets()
441 getservbyname()
442 getservbyport()
443 getservent()
444 getutxent()
445 getutxid()
446 getutxline()
447 getwc()
448 getwchar()
449 getwd() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
450 glob()
451 iconv_close()
452 iconv_open()
453 ioctl()
454 link()
455 linkat() [Added in POSIX.1-2008]
456 lio_listio() [Added in POSIX.1-2008]
457 localtime()
458 localtime_r()
459 lockf() [Added in POSIX.1-2008]
460 lseek()
461 lstat()
462 mkdir() [Added in POSIX.1-2008]
463 mkdirat() [Added in POSIX.1-2008]
464 mkdtemp() [Added in POSIX.1-2008]
465 mkfifo() [Added in POSIX.1-2008]
466 mkfifoat() [Added in POSIX.1-2008]
467 mknod() [Added in POSIX.1-2008]
468 mknodat() [Added in POSIX.1-2008]
469 mkstemp()
470 mktime()
471 nftw()
472 opendir()
473 openlog()
474 pathconf()
475 pclose()
476 perror()
477 popen()
478 posix_fadvise()
479 posix_fallocate()
480 posix_madvise()
481 posix_openpt()
482 posix_spawn()
483 posix_spawnp()
484 posix_trace_clear()
485 posix_trace_close()
486 posix_trace_create()
487 posix_trace_create_withlog()
488 posix_trace_eventtypelist_getnext_id()
489 posix_trace_eventtypelist_rewind()
490 posix_trace_flush()
491 posix_trace_get_attr()
492 posix_trace_get_filter()
493 posix_trace_get_status()
494 posix_trace_getnext_event()
495 posix_trace_open()
496 posix_trace_rewind()
497 posix_trace_set_filter()
498 posix_trace_shutdown()
499 posix_trace_timedgetnext_event()
500 posix_typed_mem_open()
501 printf()
502 psiginfo() [Added in POSIX.1-2008]
503 psignal() [Added in POSIX.1-2008]
504 pthread_rwlock_rdlock()
505 pthread_rwlock_timedrdlock()
506 pthread_rwlock_timedwrlock()
507 pthread_rwlock_wrlock()
508 putc()
509 putc_unlocked()
510 putchar()
511 putchar_unlocked()
512 puts()
513 pututxline()
514 putwc()
515 putwchar()
516 readdir()
517 readdir_r()
518 readlink() [Added in POSIX.1-2008]
519 readlinkat() [Added in POSIX.1-2008]
520 remove()
521 rename()
522 renameat() [Added in POSIX.1-2008]
523 rewind()
524 rewinddir()
525 scandir() [Added in POSIX.1-2008]
526 scanf()
527 seekdir()
528 semop()
529 setgrent()
530 sethostent()
531 setnetent()
532 setprotoent()
533 setpwent()
534 setservent()
535 setutxent()
536 sigpause() [Added in POSIX.1-2008]
537 stat()
538 strerror()
539 strerror_r()
540 strftime()
541 symlink()
542 symlinkat() [Added in POSIX.1-2008]
543 sync()
544 syslog()
545 tmpfile()
546 tmpnam()
547 ttyname()
548 ttyname_r()
549 tzset()
550 ungetc()
551 ungetwc()
552 unlink()
553 unlinkat() [Added in POSIX.1-2008]
554 utime() [Added in POSIX.1-2008]
555 utimensat() [Added in POSIX.1-2008]
556 utimes() [Added in POSIX.1-2008]
557 vdprintf() [Added in POSIX.1-2008]
558 vfprintf()
559 vfwprintf()
560 vprintf()
561 vwprintf()
562 wcsftime()
563 wordexp()
564 wprintf()
565 wscanf()
569 An implementation may also mark other functions
570 not specified in the standard as cancellation points.
571 In particular, an implementation is likely to mark
572 any nonstandard function that may block as a cancellation point.
573 (This includes most functions that can touch files.)
575 It should be noted that even if an application is not using
576 asynchronous cancellation, that calling a function from the above list
577 from an asynchronous signal handler may cause the equivalent of
578 asynchronous cancellation.
579 The underlying user code may not expect
580 asynchronous cancellation and the state of the user data may become
581 inconsistent.
582 Therefore signals should be used with caution when
583 entering a region of deferred cancellation.
584 .\" So, scanning "cancellation point" comments in the glibc 2.8 header
585 .\" files, it looks as though at least the following nonstandard
586 .\" functions are cancellation points:
587 .\" endnetgrent
588 .\" endspent
589 .\" epoll_pwait
590 .\" epoll_wait
591 .\" fcloseall
592 .\" fdopendir
593 .\" fflush_unlocked
594 .\" fgetc_unlocked
595 .\" fgetgrent
596 .\" fgetgrent_r
597 .\" fgetpwent
598 .\" fgetpwent_r
599 .\" fgets_unlocked
600 .\" fgetspent
601 .\" fgetspent_r
602 .\" fgetwc_unlocked
603 .\" fgetws_unlocked
604 .\" fputc_unlocked
605 .\" fputs_unlocked
606 .\" fputwc_unlocked
607 .\" fputws_unlocked
608 .\" fread_unlocked
609 .\" fwrite_unlocked
610 .\" gai_suspend
611 .\" getaddrinfo_a
612 .\" getdate_r
613 .\" getgrent_r
614 .\" getgrouplist
615 .\" gethostbyaddr_r
616 .\" gethostbyname2
617 .\" gethostbyname2_r
618 .\" gethostbyname_r
619 .\" gethostent_r
620 .\" getnetbyaddr_r
621 .\" getnetbyname_r
622 .\" getnetent_r
623 .\" getnetgrent
624 .\" getnetgrent_r
625 .\" getprotobyname_r
626 .\" getprotobynumber_r
627 .\" getprotoent_r
628 .\" getpw
629 .\" getpwent_r
630 .\" getservbyname_r
631 .\" getservbyport_r
632 .\" getservent_r
633 .\" getspent
634 .\" getspent_r
635 .\" getspnam
636 .\" getspnam_r
637 .\" getutmp
638 .\" getutmpx
639 .\" getw
640 .\" getwc_unlocked
641 .\" getwchar_unlocked
642 .\" initgroups
643 .\" innetgr
644 .\" mkostemp
645 .\" mkostemp64
646 .\" mkstemp64
647 .\" ppoll
648 .\" pthread_timedjoin_np
649 .\" putgrent
650 .\" putpwent
651 .\" putspent
652 .\" putw
653 .\" putwc_unlocked
654 .\" putwchar_unlocked
655 .\" rcmd
656 .\" rcmd_af
657 .\" rexec
658 .\" rexec_af
659 .\" rresvport
660 .\" rresvport_af
661 .\" ruserok
662 .\" ruserok_af
663 .\" setnetgrent
664 .\" setspent
665 .\" sgetspent
666 .\" sgetspent_r
667 .\" updwtmpx
668 .\" utmpxname
669 .\" vfscanf
670 .\" vfwscanf
671 .\" vscanf
672 .\" vsyslog
673 .\" vwscanf
674 .SS Compiling on Linux
675 On Linux, programs that use the Pthreads API should be compiled using
676 .IR "cc \-pthread" .
677 .SS Linux implementations of POSIX threads
678 Over time, two threading implementations have been provided by
679 the GNU C library on Linux:
681 .B LinuxThreads
682 This is the original Pthreads implementation.
683 Since glibc 2.4, this implementation is no longer supported.
685 .BR NPTL " (Native POSIX Threads Library)"
686 This is the modern Pthreads implementation.
687 By comparison with LinuxThreads, NPTL provides closer conformance to
688 the requirements of the POSIX.1 specification and better performance
689 when creating large numbers of threads.
690 NPTL is available since glibc 2.3.2,
691 and requires features that are present in the Linux 2.6 kernel.
693 Both of these are so-called 1:1 implementations, meaning that each
694 thread maps to a kernel scheduling entity.
695 Both threading implementations employ the Linux
696 .BR clone (2)
697 system call.
698 In NPTL, thread synchronization primitives (mutexes,
699 thread joining, and so on) are implemented using the Linux
700 .BR futex (2)
701 system call.
702 .SS LinuxThreads
703 The notable features of this implementation are the following:
704 .IP \- 3
705 In addition to the main (initial) thread,
706 and the threads that the program creates using
707 .BR pthread_create (3),
708 the implementation creates a "manager" thread.
709 This thread handles thread creation and termination.
710 (Problems can result if this thread is inadvertently killed.)
711 .IP \- 3
712 Signals are used internally by the implementation.
713 On Linux 2.2 and later, the first three real-time signals are used
714 (see also
715 .BR signal (7)).
716 On older Linux kernels,
717 .B SIGUSR1
719 .B SIGUSR2
720 are used.
721 Applications must avoid the use of whichever set of signals is
722 employed by the implementation.
723 .IP \- 3
724 Threads do not share process IDs.
725 (In effect, LinuxThreads threads are implemented as processes which share
726 more information than usual, but which do not share a common process ID.)
727 LinuxThreads threads (including the manager thread)
728 are visible as separate processes using
729 .BR ps (1).
731 The LinuxThreads implementation deviates from the POSIX.1
732 specification in a number of ways, including the following:
733 .IP \- 3
734 Calls to
735 .BR getpid (2)
736 return a different value in each thread.
737 .IP \- 3
738 Calls to
739 .BR getppid (2)
740 in threads other than the main thread return the process ID of the
741 manager thread; instead
742 .BR getppid (2)
743 in these threads should return the same value as
744 .BR getppid (2)
745 in the main thread.
746 .IP \- 3
747 When one thread creates a new child process using
748 .BR fork (2),
749 any thread should be able to
750 .BR wait (2)
751 on the child.
752 However, the implementation allows only the thread that
753 created the child to
754 .BR wait (2)
755 on it.
756 .IP \- 3
757 When a thread calls
758 .BR execve (2),
759 all other threads are terminated (as required by POSIX.1).
760 However, the resulting process has the same PID as the thread that called
761 .BR execve (2):
762 it should have the same PID as the main thread.
763 .IP \- 3
764 Threads do not share user and group IDs.
765 This can cause complications with set-user-ID programs and
766 can cause failures in Pthreads functions if an application
767 changes its credentials using
768 .BR seteuid (2)
769 or similar.
770 .IP \- 3
771 Threads do not share a common session ID and process group ID.
772 .IP \- 3
773 Threads do not share record locks created using
774 .BR fcntl (2).
775 .IP \- 3
776 The information returned by
777 .BR times (2)
779 .BR getrusage (2)
780 is per-thread rather than process-wide.
781 .IP \- 3
782 Threads do not share semaphore undo values (see
783 .BR semop (2)).
784 .IP \- 3
785 Threads do not share interval timers.
786 .IP \- 3
787 Threads do not share a common nice value.
788 .IP \- 3
789 POSIX.1 distinguishes the notions of signals that are directed
790 to the process as a whole and signals that are directed to individual
791 threads.
792 According to POSIX.1, a process-directed signal (sent using
793 .BR kill (2),
794 for example) should be handled by a single,
795 arbitrarily selected thread within the process.
796 LinuxThreads does not support the notion of process-directed signals:
797 signals may be sent only to specific threads.
798 .IP \- 3
799 Threads have distinct alternate signal stack settings.
800 However, a new thread's alternate signal stack settings
801 are copied from the thread that created it, so that
802 the threads initially share an alternate signal stack.
803 (A new thread should start with no alternate signal stack defined.
804 If two threads handle signals on their shared alternate signal
805 stack at the same time, unpredictable program failures are
806 likely to occur.)
807 .SS NPTL
808 With NPTL, all of the threads in a process are placed
809 in the same thread group;
810 all members of a thread group share the same PID.
811 NPTL does not employ a manager thread.
813 NPTL makes internal use of the first two real-time signals;
814 these signals cannot be used in applications.
816 .BR nptl (7)
817 for further details.
819 NPTL still has at least one nonconformance with POSIX.1:
820 .IP \- 3
821 Threads do not share a common nice value.
822 .\" FIXME . bug report filed for NPTL nice nonconformance
823 .\" http://bugzilla.kernel.org/show_bug.cgi?id=6258
824 .\" Sep 08: there is a patch by Denys Vlasenko to address this
825 .\" "make setpriority POSIX compliant; introduce PRIO_THREAD extension"
826 .\" Monitor this to see if it makes it into mainline.
828 Some NPTL nonconformances occur only with older kernels:
829 .IP \- 3
830 The information returned by
831 .BR times (2)
833 .BR getrusage (2)
834 is per-thread rather than process-wide (fixed in kernel 2.6.9).
835 .IP \- 3
836 Threads do not share resource limits (fixed in kernel 2.6.10).
837 .IP \- 3
838 Threads do not share interval timers (fixed in kernel 2.6.12).
839 .IP \- 3
840 Only the main thread is permitted to start a new session using
841 .BR setsid (2)
842 (fixed in kernel 2.6.16).
843 .IP \- 3
844 Only the main thread is permitted to make the process into a
845 process group leader using
846 .BR setpgid (2)
847 (fixed in kernel 2.6.16).
848 .IP \- 3
849 Threads have distinct alternate signal stack settings.
850 However, a new thread's alternate signal stack settings
851 are copied from the thread that created it, so that
852 the threads initially share an alternate signal stack
853 (fixed in kernel 2.6.16).
855 Note the following further points about the NPTL implementation:
856 .IP \- 3
857 If the stack size soft resource limit (see the description of
858 .B RLIMIT_STACK
860 .BR setrlimit (2))
861 is set to a value other than
862 .IR unlimited ,
863 then this value defines the default stack size for new threads.
864 To be effective, this limit must be set before the program
865 is executed, perhaps using the
866 .I ulimit \-s
867 shell built-in command
868 .RI ( "limit stacksize"
869 in the C shell).
870 .SS Determining the threading implementation
871 Since glibc 2.3.2, the
872 .BR getconf (1)
873 command can be used to determine
874 the system's threading implementation, for example:
876 .in +4n
878 bash$ getconf GNU_LIBPTHREAD_VERSION
879 NPTL 2.3.4
883 With older glibc versions, a command such as the following should
884 be sufficient to determine the default threading implementation:
886 .in +4n
888 bash$ $( ldd /bin/ls | grep libc.so | awk \(aq{print $3}\(aq ) | \e
889                 egrep \-i \(aqthreads|nptl\(aq
890         Native POSIX Threads Library by Ulrich Drepper et al
893 .SS Selecting the threading implementation: LD_ASSUME_KERNEL
894 On systems with a glibc that supports both LinuxThreads and NPTL
895 (i.e., glibc 2.3.\fIx\fP), the
896 .B LD_ASSUME_KERNEL
897 environment variable can be used to override
898 the dynamic linker's default choice of threading implementation.
899 This variable tells the dynamic linker to assume that it is
900 running on top of a particular kernel version.
901 By specifying a kernel version that does not
902 provide the support required by NPTL, we can force the use
903 of LinuxThreads.
904 (The most likely reason for doing this is to run a
905 (broken) application that depends on some nonconformant behavior
906 in LinuxThreads.)
907 For example:
909 .in +4n
911 bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \e
912                 awk \(aq{print $3}\(aq ) | egrep \-i \(aqthreads|nptl\(aq
913         linuxthreads\-0.10 by Xavier Leroy
916 .SH SEE ALSO
917 .ad l
919 .BR clone (2),
920 .BR fork (2),
921 .BR futex (2),
922 .BR gettid (2),
923 .BR proc (5),
924 .BR attributes (7),
925 .BR futex (7),
926 .BR nptl (7),
927 .BR sigevent (7),
928 .BR signal (7)
930 Various Pthreads manual pages, for example:
931 .BR pthread_atfork (3),
932 .BR pthread_attr_init (3),
933 .BR pthread_cancel (3),
934 .BR pthread_cleanup_push (3),
935 .BR pthread_cond_signal (3),
936 .BR pthread_cond_wait (3),
937 .BR pthread_create (3),
938 .BR pthread_detach (3),
939 .BR pthread_equal (3),
940 .BR pthread_exit (3),
941 .BR pthread_key_create (3),
942 .BR pthread_kill (3),
943 .BR pthread_mutex_lock (3),
944 .BR pthread_mutex_unlock (3),
945 .BR pthread_mutexattr_destroy (3),
946 .BR pthread_mutexattr_init (3),
947 .BR pthread_once (3),
948 .BR pthread_spin_init (3),
949 .BR pthread_spin_lock (3),
950 .BR pthread_rwlockattr_setkind_np (3),
951 .BR pthread_setcancelstate (3),
952 .BR pthread_setcanceltype (3),
953 .BR pthread_setspecific (3),
954 .BR pthread_sigmask (3),
955 .BR pthread_sigqueue (3),
957 .BR pthread_testcancel (3)