2 .\" Copyright (c) 2005 by Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved.
25 .\" Translated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
26 .\" Updated 2006-04-15, Akihiro MOTOKI, LDP v2.29
27 .\" Updated 2007-01-05, Akihiro MOTOKI, LDP v2.43
28 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
29 .\" Updated 2008-11-05, Akihiro MOTOKI, LDP v3.12
30 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
31 .\" Updated 2008-12-26, Akihiro MOTOKI, LDP v3.14
33 .\"WORD: manager thread 管理スレッド
34 .\"WORD: thread group スレッド・グループ
35 .\"WORD: real-time signal リアルタイムシグナル
36 .\"WORD: non-conformant 標準非準拠の
37 .\"WORD: alternate signal stack 代替シグナルスタック
39 .TH PTHREADS 7 2008-11-18 "Linux" "Linux Programmer's Manual"
42 .\"O pthreads \- POSIX threads
43 pthreads \- POSIX スレッド
46 .\"O POSIX.1 specifies a set of interfaces (functions, header files) for
47 .\"O threaded programming commonly known as POSIX threads, or Pthreads.
48 .\"O A single process can contain multiple threads,
49 .\"O all of which are executing the same program.
50 .\"O These threads share the same global memory (data and heap segments),
51 .\"O but each thread has its own stack (automatic variables).
52 POSIX.1 は、一般に POSIX スレッドや Pthreads として知られる
53 スレッド・プログラミングのインタフェース群 (関数、ヘッダファイル)
54 を規定している。一つのプロセスは複数のスレッドを持つことができ、
56 これらのスレッドは同じ大域メモリ (データとヒープ領域) を共有するが、
57 各スレッドは自分専用のスタック (自動変数) を持つ。
59 .\"O POSIX.1 also requires that threads share a range of other attributes
60 .\"O (i.e., these attributes are process-wide rather than per-thread):
61 POSIX.1 はスレッド間でどのような属性を共有するかについても定めている
62 (つまり、これらの属性はスレッド単位ではなくプロセス全体で共通である):
67 .\"O parent process ID
70 .\"O process group ID and session ID
73 .\"O controlling terminal
76 .\"O user and group IDs
79 .\"O open file descriptors
82 .\"O record locks (see
88 .\"O signal dispositions
91 .\"O file mode creation mask
96 .\"O current directory
107 .\"O and POSIX timers
109 .RB ( timer_create (2))
113 .RB ( setpriority (2))
119 .\"O measurements of the consumption of CPU time
120 .\"O .RB ( times (2))
122 .\"O .RB ( getrusage (2))
129 .\"O As well as the stack, POSIX.1 specifies that various other
130 .\"O attributes are distinct for each thread, including:
131 スタックについても、POSIX.1 はどのような属性が
132 個々のスレッドで独立に管理されるかを規定している:
143 .RB ( pthread_sigmask (3))
151 .\"O alternate signal stack
153 .RB ( sigaltstack (2))
155 .\"O real-time scheduling policy and priority
156 リアルタイム・スケジューリングのポリシーと優先度
157 .RB ( sched_setscheduler (2)
160 .BR sched_setparam (2))
162 .\"O The following Linux-specific features are also per-thread:
163 以下の Linux 特有の機能もスレッド単位である:
165 .\"O capabilities (see
166 .\"O .BR capabilities (7))
168 .RB ( capabilities (7)
173 .RB ( sched_setaffinity (2))
174 .\"O .SS "Pthreads function return values"
175 .SS "pthreads 関数の返り値"
176 .\"O Most pthreads functions return 0 on success, and an error number of failure.
177 .\"O Note that the pthreads functions do not set
179 .\"O For each of the pthreads functions that can return an error,
180 .\"O POSIX.1-2001 specifies that the function can never fail with the error
182 ほとんどの pthreads 関数は成功すると 0 を返し、
188 エラーを返す可能性のある pthreads 関数がエラー
190 で失敗することは決してないと規定している。
193 .\"O Each of the threads in a process has a unique thread identifier
194 .\"O (stored in the type
195 .\"O .IR pthread_t ).
196 .\"O This identifier is returned to the caller of
197 .\"O .BR pthread_create (3),
198 .\"O and a thread can obtain its own thread identifier using
199 .\"O .BR pthread_self (3).
200 .\"O Thread IDs are only guaranteed to be unique within a process.
201 .\"O A thread ID may be reused after a terminated thread has been joined,
202 .\"O or a detached thread has terminated.
203 .\"O In all pthreads functions that accept a thread ID as an argument,
204 .\"O that ID by definition refers to a thread in
205 .\"O the same process as the caller.
210 .BR pthread_create (3)
211 の呼び出し元に返される。また、スレッドは自身のスレッド識別子を
214 スレッド ID の一意性が保証されるのは、一つのプロセス内においてのみである。
215 終了したスレッドが join された後では、スレッド ID は再利用される可能性がある。
216 スレッド ID を引き数に取る全てのスレッド関数において、
217 その ID は呼び出し元と同じプロセス内の一つのスレッドを参照する。
218 .\"O .SS "Thread-safe functions"
220 .\"O A thread-safe function is one that can be safely
221 .\"O (i.e., it will deliver the same results regardless of whether it is)
222 .\"O called from multiple threads at the same time.
223 スレッドセーフな関数は、複数のスレッドから同時に呼び出しても安全な
224 (すなわち、同時に呼び出されたかに関わらず、同じ結果を返す) 関数のことである。
226 .\"O POSIX.1-2001 and POSIX.1-2008 require that all functions specified
227 .\"O in the standard shall be thread-safe,
228 .\"O except for the following functions:
229 POSIX.1-2001 と POSIX.1-2008では、一部の例外を除き、
230 標準で規定されている全ての関数がスレッドセーフであることを要求している。
239 .\"O ctermid() if passed a non-NULL argument
240 ctermid() (NULL でない引き数を渡された場合)
254 .\"O ecvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
255 ecvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
260 .\"O fcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
261 fcvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
263 .\"O gcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
264 gcvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
272 .\"O gethostbyaddr() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
273 .\"O gethostbyname() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
274 gethostbyaddr() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
275 gethostbyname() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
322 .\"O strsignal() [Added in POSIX.1-2008]
323 strsignal() [POSIX.1-2008 で追加された]
325 .\"O system() [Added in POSIX.1-2008]
326 system() [POSIX.1-2008 で追加された]
327 .\"O tmpnam() if passed a non-NULL argument
328 tmpnam() (NULL でない引き数を渡された場合)
331 .\"O wcrtomb() if its final argument is NULL
332 wcrtomb() (最後の引き数が NULL の場合)
333 .\"O wcsrtombs() if its final argument is NULL
334 wcsrtombs() (最後の引き数が NULL の場合)
339 .\"O .SS Cancellation Points
340 .SS 取り消しポイント (cancellation points)
341 .\"O POSIX.1 specifies that certain functions must,
342 .\"O and certain other functions may, be cancellation points.
343 .\"O If a thread is cancelable, its cancelability type is deferred,
344 .\"O and a cancellation request is pending for the thread,
345 .\"O then the thread is canceled when it calls a function
346 .\"O that is a cancellation point.
347 POSIX.1 の規定では、特定の関数は取り消しポイントでなければならず、
348 他の特定の関数は取り消しポイントであってもよいとされている。
349 あるスレッドが取り消し可能で、その取り消し種別 (cancelability type)
350 が延期 (deferred) で、そのスレッドに対する取り消し要求が処理待ちの場合、
351 取り消しポイントである関数を呼び出した時点で、そのスレッドのキャンセルが
354 .\"O The following functions are required to be cancellation points by
355 .\"O POSIX.1-2001 and/or POSIX.1-2008:
356 POSIX.1-2001 と POSIX.1-2008 の両方、もしくはいずれか一方では、
357 以下の関数は、取り消しポイント (cancellation points) で
361 .\" Document the list of all functions that are cancellation points in glibc
385 .\"O openat() [Added in POSIX.1-2008]
386 openat() [POSIX.1-2008 で追加された]
391 pthread_cond_timedwait()
409 .\"O sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)]
410 sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)]
418 .\"O usleep() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
419 usleep() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)]
428 .\"O The following functions may be cancellation points according to
429 .\"O POSIX.1-2001 and/or POSIX.1-2008:
430 POSIX.1-2001 と POSIX.1-2008 の両方、もしくはいずれか一方では、
431 以下の関数は、取り消しポイント (cancellation points) で
442 .\"O chmod() [Added in POSIX.1-2008]
443 .\"O chown() [Added in POSIX.1-2008]
444 chmod() [POSIX.1-2008 で追加された]
445 chown() [POSIX.1-2008 で追加された]
459 .\"O dprintf() [Added in POSIX.1-2008]
460 dprintf() [POSIX.1-2008 で追加された]
468 .\"O faccessat() [Added in POSIX.1-2008]
469 .\"O fchmod() [Added in POSIX.1-2008]
470 .\"O fchmodat() [Added in POSIX.1-2008]
471 .\"O fchown() [Added in POSIX.1-2008]
472 .\"O fchownat() [Added in POSIX.1-2008]
473 faccessat() [POSIX.1-2008 で追加された]
474 fchmod() [POSIX.1-2008 で追加された]
475 fchmodat() [POSIX.1-2008 で追加された]
476 fchown() [POSIX.1-2008 で追加された]
477 fchownat() [POSIX.1-2008 で追加された]
479 .\"O fcntl() (for any value of cmd argument)
480 fcntl() (cmd 引き数が何であっても)
502 .\"O fstatat() [Added in POSIX.1-2008]
503 fstatat() [POSIX.1-2008 で追加された]
507 .\"O futimens() [Added in POSIX.1-2008]
508 futimens() [POSIX.1-2008 で追加された]
519 .\"O getdelim() [Added in POSIX.1-2008]
520 getdelim() [POSIX.1-2008 で追加された]
526 .\"O gethostbyaddr() [SUSv3 only (function removed in POSIX.1-2008)]
527 .\"O gethostbyname() [SUSv3 only (function removed in POSIX.1-2008)]
528 gethostbyaddr() [SUSv3 のみ (この関数は POSIX.1-2008 で削除されている)]
529 gethostbyname() [SUSv3 のみ (この関数は POSIX.1-2008 で削除されている)]
533 .\"O getline() [Added in POSIX.1-2008]
534 getline() [POSIX.1-2008 で追加された]
541 .\"O getopt() (if opterr is nonzero)
542 getopt() (opterr が 0 以外の場合)
560 .\"O getwd() [SUSv3 only (function removed in POSIX.1-2008)]
561 getwd() [SUSv3 のみ (この関数は POSIX.1-2008 で削除されている)]
567 .\"O linkat() [Added in POSIX.1-2008]
568 .\"O lio_listio() [Added in POSIX.1-2008]
569 linkat() [POSIX.1-2008 で追加された]
570 lio_listio() [POSIX.1-2008 で追加された]
573 .\"O lockf() [Added in POSIX.1-2008]
574 lockf() [POSIX.1-2008 で追加された]
577 .\"O mkdir() [Added in POSIX.1-2008]
578 .\"O mkdirat() [Added in POSIX.1-2008]
579 .\"O mkdtemp() [Added in POSIX.1-2008]
580 .\"O mkfifo() [Added in POSIX.1-2008]
581 .\"O mkfifoat() [Added in POSIX.1-2008]
582 .\"O mknod() [Added in POSIX.1-2008]
583 .\"O mknodat() [Added in POSIX.1-2008]
584 mkdir() [POSIX.1-2008 で追加された]
585 mkdirat() [POSIX.1-2008 で追加された]
586 mkdtemp() [POSIX.1-2008 で追加された]
587 mkfifo() [POSIX.1-2008 で追加された]
588 mkfifoat() [POSIX.1-2008 で追加された]
589 mknod() [POSIX.1-2008 で追加された]
590 mknodat() [POSIX.1-2008 で追加された]
609 posix_trace_create_withlog()
610 posix_trace_eventtypelist_getnext_id()
611 posix_trace_eventtypelist_rewind()
613 posix_trace_get_attr()
614 posix_trace_get_filter()
615 posix_trace_get_status()
616 posix_trace_getnext_event()
619 posix_trace_set_filter()
620 posix_trace_shutdown()
621 posix_trace_timedgetnext_event()
622 posix_typed_mem_open()
624 .\"O psiginfo() [Added in POSIX.1-2008]
625 .\"O psignal() [Added in POSIX.1-2008]
626 psiginfo() [POSIX.1-2008 で追加された]
627 psignal() [POSIX.1-2008 で追加された]
628 pthread_rwlock_rdlock()
629 pthread_rwlock_timedrdlock()
630 pthread_rwlock_timedwrlock()
631 pthread_rwlock_wrlock()
642 .\"O readlink() [Added in POSIX.1-2008]
643 .\"O readlinkat() [Added in POSIX.1-2008]
644 readlink() [POSIX.1-2008 で追加された]
645 readlinkat() [POSIX.1-2008 で追加された]
648 .\"O renameat() [Added in POSIX.1-2008]
649 renameat() [POSIX.1-2008 で追加された]
652 .\"O scandir() [Added in POSIX.1-2008]
653 scandir() [POSIX.1-2008 で追加された]
664 .\"O sigpause() [Added in POSIX.1-2008]
665 sigpause() [POSIX.1-2008 で追加された]
671 .\"O symlinkat() [Added in POSIX.1-2008]
672 symlinkat() [POSIX.1-2008 で追加された]
683 .\"O unlinkat() [Added in POSIX.1-2008]
684 .\"O utime() [Added in POSIX.1-2008]
685 .\"O utimensat() [Added in POSIX.1-2008]
686 .\"O utimes() [Added in POSIX.1-2008]
687 .\"O vdprintf() [Added in POSIX.1-2008]
688 unlinkat() [POSIX.1-2008 で追加された]
689 utime() [POSIX.1-2008 で追加された]
690 utimensat() [POSIX.1-2008 で追加された]
691 utimes() [POSIX.1-2008 で追加された]
692 vdprintf() [POSIX.1-2008 で追加された]
704 .\"O An implementation may also mark other functions
705 .\"O not specified in the standard as cancellation points.
706 .\"O In particular, an implementation is likely to mark
707 .\"O any nonstandard function that may block as a cancellation point.
708 .\"O (This includes most functions that can touch files.)
709 実装時に、標準規格で規定されていないその他の関数を取り消しポイント
711 特に、停止 (block) する可能性がある非標準の関数を取り消しポイントと
713 (ファイルを扱う可能性のあるほとんどの関数がこれに含まれる)。
714 .\" So, scanning "cancellation point" comments in the glibc 2.8 header
715 .\" files, it looks as though at least the following nonstandard
716 .\" functions are cancellation points:
756 .\" getprotobynumber_r
771 .\" getwchar_unlocked
778 .\" pthread_timedjoin_np
784 .\" putwchar_unlocked
804 .\"O .SS "Compiling on Linux"
806 .\"O On Linux, programs that use the Pthreads API should be compiled using
807 .\"O .IR "cc \-pthread" .
808 Linux では、Pthreads API を用いたプログラムは
811 .\"O .SS "Linux Implementations of POSIX Threads"
812 .SS "POSIX スレッドの Linux での実装"
813 .\"O Over time, two threading implementations have been provided by
814 .\"O the GNU C library on Linux:
815 これまで、2つのスレッドの実装が Linux の GNU C ライブラリにより
819 .\"O This is the original Pthreads implementation.
820 .\"O Since glibc 2.4, this implementation is no longer supported.
822 glibc 2.4 以降は、この実装はもはやサポートされていない。
824 .BR NPTL " (Native POSIX Threads Library)"
825 .\"O This is the modern Pthreads implementation.
826 .\"O By comparison with LinuxThreads, NPTL provides closer conformance to
827 .\"O the requirements of the POSIX.1 specification and better performance
828 .\"O when creating large numbers of threads.
829 .\"O NPTL is available since glibc 2.3.2,
830 .\"O and requires features that are present in the Linux 2.6 kernel.
831 新しい Pthreads の実装。LinuxThreads と比べると、
832 NPTL は POSIX.1 の要求仕様への準拠の度合いが高く、
834 NPTL は glibc 2.3.2 以降で利用可能である。
835 NPTL を利用するには Linux 2.6 カーネルに実装されている機能が必要である。
837 .\"O Both of these are so-called 1:1 implementations, meaning that each
838 .\"O thread maps to a kernel scheduling entity.
839 どちらの実装もいわゆる 1:1 実装、すなわち個々のスレッドが
840 カーネルのスケジューリング実体にマッピングされる。
841 .\"O Both threading implementations employ the Linux
844 .\"O In NPTL, thread synchronization primitives (mutexes,
845 .\"O thread joining, etc.) are implemented using the Linux
851 NPTL では、スレッド同期の基本機構 (mutex や スレッドの join 等) は
856 .\"O The notable features of this implementation are the following:
859 .\"O In addition to the main (initial) thread,
860 .\"O and the threads that the program creates using
861 .\"O .BR pthread_create (3),
862 .\"O the implementation creates a "manager" thread.
863 .\"O This thread handles thread creation and termination.
864 .\"O (Problems can result if this thread is inadvertently killed.)
865 メインスレッド (最初のスレッド) とプログラムが
866 .BR pthread_create (3)
868 この実装では「管理 (manager)」スレッドが作成される。
869 管理スレッドはスレッドの作成と終了を取り扱う
870 (このスレッドがうっかり kill されると、問題が起こることがある)。
872 .\"O Signals are used internally by the implementation.
873 .\"O On Linux 2.2 and later, the first three real-time signals are used
875 .\"O .BR signal (7)).
876 .\"O On older Linux kernels,
881 .\"O Applications must avoid the use of whichever set of signals is
882 .\"O employed by the implementation.
883 この実装では内部でシグナルを使用している。
884 Linux 2.2 以降では、リアルタイムシグナルのうち最初の 3つが使われる
892 アプリケーションは、スレッド実装で利用されているシグナルを
895 .\"O Threads do not share process IDs.
896 .\"O (In effect, LinuxThreads threads are implemented as processes which share
897 .\"O more information than usual, but which do not share a common process ID.)
898 .\"O LinuxThreads threads (including the manager thread)
899 .\"O are visible as separate processes using
902 (実際には LinuxThreads のスレッドは通常よりは情報を共有するプロセスとして
903 実装されているが、一つの共通のプロセス ID を共有してはいない)。
904 (管理スレッドを含む) LinuxThreads スレッドは
908 .\"O The LinuxThreads implementation deviates from the POSIX.1
909 .\"O specification in a number of ways, including the following:
910 LinuxThreads の実装では POSIX.1 仕様から逸脱している点が
915 .\"O return a different value in each thread.
917 を呼び出したときに、スレッド毎に異なる値が返される。
921 .\"O in threads other than the main thread return the process ID of the
922 .\"O manager thread; instead
924 .\"O in these threads should return the same value as
926 .\"O in the main thread.
929 を呼び出すと、管理スレッドのプロセス ID が返される。
936 .\"O When one thread creates a new child process using
938 .\"O any thread should be able to
941 .\"O However, the implementation only allows the thread that
942 .\"O created the child to
950 できるべきである。しかしながら、この実装では子プロセスを作成した
955 .\"O When a thread calls
957 .\"O all other threads are terminated (as required by POSIX.1).
958 .\"O However, the resulting process has the same PID as the thread that called
960 .\"O it should have the same PID as the main thread.
963 を呼び出した場合、他のスレッドは全て終了される (POSIX.1 の仕様通り)。
966 を呼んだスレッドと同じ PID を持つ。正しくは
967 メインスレッドと同じ PID を持つべきである。
969 .\"O Threads do not share user and group IDs.
970 .\"O This can cause complications with set-user-ID programs and
971 .\"O can cause failures in Pthreads functions if an application
972 .\"O changes its credentials using
975 スレッド間でユーザ ID とグループ ID が共有されない
976 このことは、set-user-ID プログラムで面倒な事態を招いたり、
979 などを使って信用情報 (credentials) を変更した場合に
980 Pthreads 関数が失敗する原因となる。
982 .\"O Threads do not share a common session ID and process group ID.
983 スレッド間で共通のセッション ID やプロセスグループ ID を共有しない。
985 .\"O Threads do not share record locks created using
989 を使って作成されるレコード・ロックを共有しない。
991 .\"O The information returned by
994 .\"O .BR getrusage (2)
995 .\"O is per-thread rather than process-wide.
999 が返す情報がプロセス全体の情報でなくスレッド単位の情報である。
1001 .\"O Threads do not share semaphore undo values (see
1002 .\"O .BR semop (2)).
1007 .\"O Threads do not share interval timers.
1008 スレッド間でインターバル・タイマを共有しない。
1010 .\"O Threads do not share a common nice value.
1011 スレッドは共通の nice 値を共有しない。
1013 .\"O POSIX.1 distinguishes the notions of signals that are directed
1014 .\"O to the process as a whole and signals that are directed to individual
1016 .\"O According to POSIX.1, a process-directed signal (sent using
1018 .\"O for example) should be handled by a single,
1019 .\"O arbitrarily selected thread within the process.
1020 .\"O LinuxThreads does not support the notion of process-directed signals:
1021 .\"O signals may only be sent to specific threads.
1022 POSXI.1 では、全体としてのプロセスに送られるシグナルと、
1023 個別のスレッドに送られるシグナルを区別して考えている。
1024 POSIX.1 によると、プロセスに送られたシグナル (例えば
1026 を使って送る) は、そのプロセスに属すスレッドのうち
1027 勝手に (arbitrarily) に選択された一つのスレッドにより処理される
1028 ことになっている。LinuxThreads はプロセスに送られるシグナルの
1029 概念に対応しておらず、シグナルは特定のスレッドにだけ送ることができる。
1031 .\"O Threads have distinct alternate signal stack settings.
1032 .\"O However, a new thread's alternate signal stack settings
1033 .\"O are copied from the thread that created it, so that
1034 .\"O the threads initially share an alternate signal stack.
1035 .\"O (A new thread should start with no alternate signal stack defined.
1036 .\"O If two threads handle signals on their shared alternate signal
1037 .\"O stack at the same time, unpredictable program failures are
1038 .\"O likely to occur.)
1039 スレッドはそれぞれの独自の代替シグナルスタックの設定を持つ。
1040 しかし、新しいスレッドの代替シグナルスタックの設定は
1041 そのスレッドを作成したスレッドからコピーされ、そのため
1042 スレッドは最初は一つの代替シグナルスタックを共有する。
1043 (仕様では、新しいスレッドは代替シグナルスタックが定義されていない状態
1045 2つのスレッドが共有されている代替シグナルスタック上で同時に
1046 シグナルの処理を行った場合、予測不可能なプログラムのエラーが
1049 .\"O With NPTL, all of the threads in a process are placed
1050 .\"O in the same thread group;
1051 .\"O all members of a thread group share the same PID.
1052 .\"O NPTL does not employ a manager thread.
1053 .\"O NPTL makes internal use of the first two real-time signals
1055 .\"O .BR signal (7));
1056 .\"O these signals cannot be used in applications.
1057 NPTL では、一つのプロセスの全てのスレッドは同じスレッド・グループ
1058 に属する; スレッド・グループの全メンバーは同じ PID を共有する。
1059 NPTL は管理スレッド (manager thread) を利用しない。
1060 NPTL は内部でリアルタイムシグナルのうち最初の 2つの番号を使用しており
1062 参照)、これらのシグナルはアプリケーションでは使用できない。
1064 .\"O NPTL still has at least one nonconformance with POSIX.1:
1065 NPTL にも POSIX.1 に準拠していない点が少なくとも一つある:
1067 .\"O Threads do not share a common nice value.
1068 スレッドは共通の nice 値を共有しない。
1069 .\" FIXME . bug report filed for NPTL nice nonconformance
1070 .\" http://bugzilla.kernel.org/show_bug.cgi?id=6258
1071 .\" Sep 08: there is a patch by Denys Vlasenko to address this
1072 .\" "make setpriority POSIX compliant; introduce PRIO_THREAD extension"
1073 .\" Monitor this to see if it makes it into mainline.
1075 .\"O Some NPTL nonconformances only occur with older kernels:
1076 NPTL の標準非準拠な点のうちいくつかは以前のカーネルでのみ発生する:
1078 .\"O The information returned by
1081 .\"O .BR getrusage (2)
1082 .\"O is per-thread rather than process-wide (fixed in kernel 2.6.9).
1086 が返す情報がプロセス全体の情報でなくスレッド単位の情報である
1087 (カーネル 2.6.9 で修正された)。
1089 .\"O Threads do not share resource limits (fixed in kernel 2.6.10).
1090 スレッド間でリソース制限を共有しない (カーネル 2.6.10 で修正された)。
1092 .\"O Threads do not share interval timers (fixed in kernel 2.6.12).
1093 スレッド間でインターバル・タイマを共有しない
1094 (カーネル 2.6.12 で修正された)。
1096 .\"O Only the main thread is permitted to start a new session using
1098 .\"O (fixed in kernel 2.6.16).
1101 を使って新しいセッションを開始することができる
1102 (カーネル 2.6.16 で修正された)。
1104 .\"O Only the main thread is permitted to make the process into a
1105 .\"O process group leader using
1106 .\"O .BR setpgid (2)
1107 .\"O (fixed in kernel 2.6.16).
1110 を使ってそのプロセスをプロセス・グループ・リーダーにすることができる
1111 (カーネル 2.6.16 で修正された)。
1113 .\"O Threads have distinct alternate signal stack settings.
1114 .\"O However, a new thread's alternate signal stack settings
1115 .\"O are copied from the thread that created it, so that
1116 .\"O the threads initially share an alternate signal stack
1117 .\"O (fixed in kernel 2.6.16).
1118 スレッドはそれぞれの独自の代替シグナルスタックの設定を持つ。
1119 しかし、新しいスレッドの代替シグナルスタックの設定は
1120 そのスレッドを作成したスレッドからコピーされ、そのため
1121 スレッドは最初は一つの代替シグナルスタックを共有する
1122 (カーネル 2.6.16 で修正された)。
1124 .\"O Note the following further points about the NPTL implementation:
1125 NPTL の実装では以下の点についても注意すること:
1127 .\"O If the stack size soft resource limit (see the description of
1128 .\"O .B RLIMIT_STACK
1130 .\"O .BR setrlimit (2))
1131 .\"O is set to a value other than
1132 .\"O .IR unlimited ,
1133 .\"O then this value defines the default stack size for new threads.
1134 .\"O To be effective, this limit must be set before the program
1135 .\"O is executed, perhaps using the
1137 .\"O shell built-in command
1138 .\"O .RI ( "limit stacksize"
1139 .\"O in the C shell).
1140 スタックサイズのリソースのソフト・リミット
1146 以外の値に設定されている場合、ソフト・リミットの値が
1147 新しいスレッドのデフォルトのスタックサイズとなる。
1148 設定を有効にするためには、プログラムを実行する前にリミット値を
1149 設定しておかなければならない。たいていは、シェルの組み込みコマンドの
1152 .IR "limit stacksize" )
1154 .\"O .SS "Determining the Threading Implementation"
1156 .\"O Since glibc 2.3.2, the
1157 .\"O .BR getconf (1)
1158 .\"O command can be used to determine
1159 .\"O the system's threading implementation, for example:
1163 システムのスレッド実装を判定することができる。
1168 bash$ getconf GNU_LIBPTHREAD_VERSION
1173 .\"O With older glibc versions, a command such as the following should
1174 .\"O be sufficient to determine the default threading implementation:
1175 ぞれ以前の glibc のバージョンでは、以下のようなコマンドで
1176 デフォルトのスレッド実装を判定することができる。
1180 bash$ $( ldd /bin/ls | grep libc.so | awk \(aq{print $3}\(aq ) | \\
1181 egrep \-i \(aqthreads|ntpl\(aq
1182 Native POSIX Threads Library by Ulrich Drepper et al
1185 .\"O .SS "Selecting the Threading Implementation: LD_ASSUME_KERNEL"
1186 .SS "スレッドの実装の選択: LD_ASSUME_KERNEL"
1187 .\"O On systems with a glibc that supports both LinuxThreads and NPTL
1188 .\"O (i.e., glibc 2.3.\fIx\fP), the
1189 .\"O .B LD_ASSUME_KERNEL
1190 .\"O environment variable can be used to override
1191 .\"O the dynamic linker's default choice of threading implementation.
1192 .\"O This variable tells the dynamic linker to assume that it is
1193 .\"O running on top of a particular kernel version.
1194 LinuxThreads と NPTL の両方をサポートしている glibc
1195 (glibc 2.3.\fIx\fP) があるシステムでは、
1197 環境変数を使うことで、動的リンカがデフォルトで
1198 選択するスレッド実装を上書きすることができる。
1199 この変数により、動的リンカが特定のバージョンのカーネル上で
1201 .\"O By specifying a kernel version that does not
1202 .\"O provide the support required by NPTL, we can force the use
1203 .\"O of LinuxThreads.
1204 .\"O (The most likely reason for doing this is to run a
1205 .\"O (broken) application that depends on some nonconformant behavior
1206 .\"O in LinuxThreads.)
1208 NPTL が必要とするサポート機能を提供していないカーネルバージョンを
1209 指定することで、強制的に LinuxThreads を使うことができる
1210 (このようなことをする最もありそうな場面は、
1211 LinuxThreads の標準非準拠な振舞いに依存する (壊れた) アプリケーション
1217 bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \\
1218 awk \(aq{print $3}\(aq ) | egrep \-i \(aqthreads|ntpl\(aq
1219 linuxthreads-0.10 by Xavier Leroy
1231 .\"O and various Pthreads manual pages, for example:
1232 および Pthreads の各種マニュアルページ、例えば:
1233 .BR pthread_attr_init (3),
1234 .BR pthread_atfork (3),
1235 .BR pthread_cancel (3),
1236 .BR pthread_cleanup_push (3),
1237 .BR pthread_cond_signal (3),
1238 .BR pthread_cond_wait (3),
1239 .BR pthread_create (3),
1240 .BR pthread_detach (3),
1241 .BR pthread_equal (3),
1242 .BR pthread_exit (3),
1243 .BR pthread_key_create (3),
1244 .BR pthread_kill (3),
1245 .BR pthread_mutex_lock (3),
1246 .BR pthread_mutex_unlock (3),
1247 .BR pthread_once (3),
1248 .BR pthread_setcancelstate (3),
1249 .BR pthread_setcanceltype (3),
1250 .BR pthread_setspecific (3),
1251 .BR pthread_sigmask (3),
1253 .BR pthread_testcancel (3)