.\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk .\" .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2012-05-04, Akihiro MOTOKI .\" .TH PTHREAD_JOIN 3 2008\-11\-27 Linux "Linux Programmer's Manual" .SH 名前 pthread_join \- 終了したスレッドを join する .SH 書式 .nf \fB#include \fP \fBint pthread_join(pthread_t \fP\fIthread\fP\fB, void **\fP\fIretval\fP\fB);\fP .fi .sp \fI\-pthread\fP を付けてコンパイルとリンクを行う。 .SH 説明 \fBpthread_join\fP() 関数は、\fIthread\fP で指定されたスレッドが 終了するのを待つ。そのスレッドがすでに終了している場合、 \fBpthread_join\fP() はすぐに返る。 \fIthread\fP で指定されたスレッドは join 可能でなければならない。 \fIretval\fP が NULL でない場合、 \fBpthread_join\fP() は対象スレッドの終了 ステータス (すなわち、対象スレッドが \fBpthread_exit\fP(3) に渡した値) を \fI*retval\fP が指す場所にコピーする。対象スレッドがキャンセルされた場合、 \fI*retval\fP には \fBPTHREAD_CANCELED\fP が格納される。 複数のスレッドが同時に同じスレッドを join しようとした場合、その結果 は不定である。\fBpthread_join\fP() を呼び出しているスレッドがキャンセル された場合、対象スレッドは join 可能のままとなる (detached 状態には ならない)。 .SH 返り値 成功すると、 \fBpthread_join\fP() は 0 を返す。 エラーの場合、エラー番号を返す。 .SH エラー .TP \fBEDEADLK\fP .\" The following verified by testing on glibc 2.8/NPTL: .\" The following verified by testing on glibc 2.8/NPTL: デッドロックが検出された (例えば、二つのスレッドが互いに join しようと した場合)、または \fIthread\fP に呼び出したスレッドが指定されている。 .TP \fBEINVAL\fP \fIthread\fP が join 可能なスレッドではない。 .TP \fBEINVAL\fP .\" POSIX.1-2001 does not specify this error case. 別のスレッドがすでにこのスレッドの join 待ちである。 .TP \fBESRCH\fP ID が \fIthread\fP のスレッドが見つからなかった。 .SH 準拠 POSIX.1\-2001. .SH 注意 \fBpthread_join\fP() の呼び出しが成功した場合は、 呼び出し側には、対象スレッドが終了していることが保証される。 すでに join されたスレッドを join した場合の結果は不定である。 join 可能なスレッド (detached 状態でないスレッド) の join に失敗した場合、 "ゾンビスレッド (zombie thread)" が生成される。 各ゾンビスレッドはシステムリソースをいくらかは消費し、 ゾンビスレッドがたくさん生成されてしまうと、 新しいスレッド (やプロセス) がそれ以上作成できなくなってしまうので、 このようなことが起きるのは避けること。 pthreads には、 \fIwaitpid(\-1,\ &status,\ 0)\fP、つまり "終了されたスレッドのどれかを join する" といった機能はない。 この機能が必要だと思うような場合には、おそらく 自分のアプリケーションの設計を考え直す必要があるだろう。 プロセス内の全てのスレッドは対等であり、 どのスレッドでもプロセス内の他のスレッドを join できる。 .SH 例 \fBpthread_create\fP(3) を参照。 .SH 関連項目 \fBpthread_cancel\fP(3), \fBpthread_create\fP(3), \fBpthread_detach\fP(3), \fBpthread_exit\fP(3), \fBpthread_tryjoin_np\fP(3), \fBpthreads\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。