.\" Copyright (C) 1996-1999 Free Software Foundation, Inc. .\" .\" 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. .\" .\" Permission is granted to copy and distribute translations of this .\" manual into another language, under the above conditions for modified .\" versions, except that this permission notice may be stated in a .\" translation approved by the Foundation. .\" .\" Copyright (C) 1996 Xavier Leroy. .\" .\" Japanese Version Copyright (C) 2002-2003 Suzuki Takashi .\" all rights reserved. .\" Translated Tue Dec 31 14:14:12 JST 2002 .\" by Suzuki Takashi. .\" .\"WORD: terminate 終了 .\"WORD: cancellation 取り消し .\"WORD: calling thread 呼び出しスレッド .\"WORD: suspend 停止 .\"WORD: exit 終了 .\"WORD: join 合流 .\"WORD: thread descriptor スレッドディスクリプタ .\" .\" .TH PTHREAD_JOIN 3 LinuxThreads .SH "名前" pthread_join \- 別のスレッドの終了を待つ .SH "書式" .B #include .BI "int pthread_join(pthread_t " th ", void **" thread_return ");" .SH "説明" .B "pthread_join" は、 呼び出しスレッドの実行を停止し、 .I "th" で指定したスレッドが .BR "pthread_exit" (3) を呼び出して終了するか、取り消しされて終了するのを待つ。 .I "thread_return" が .B "NULL" でないときには、 .I "th" の返り値が .I "thread_return" で指し示される領域に格納される。 .I "th" の返り値は、 .BR "pthread_exit" (3) に与えられた引数、または .BR "PTHREAD_CANCELED" ( .I "th" が取り消しされた場合 ) である。 合流 (join) されるスレッド .B "th" は、合流可能 (joinable) な状態でなければならない。 すなわち、 .BR "pthread_detach" (3) を使用してデタッチ (detach) されていたり、 .BR "pthread_create" (3) で属性 .B "PTHREAD_CREATE_DETACHED" を与えられていたりしてはならない。 合流可能なスレッドが終了しても、 別のスレッドがそのスレッドに対して .B "pthread_join" を呼び出すまでは、 そのメモリ資源 (スレッドディスクリプタとスタック) は解放されない。 したがって、メモリリークを防ぐためには、 合流可能なスレッドそれぞれに対して .B "pthread_join" を 1 回ずつ呼び出さなければならない。 あるスレッドの終了を待つことができるスレッドは高々 1 つである。 すでに別のスレッドが終了を待っているスレッド .I "th" に対して .B "pthread_join" を呼び出した場合、エラーが返る。 .SH "取り消し" .B "pthread_join" は取り消しポイントである。 スレッドが .B "pthread_join" で停止しているときに取り消しされると、 直ちに実行が再開されて スレッド .I "th" が終了するのを待つことなく取り消しが実行される。 取り消しが .B "pthread_join" で起こった場合には、 スレッド .I "th" は合流されずに残ることになる。 .SH "返り値" 成功すると、 .I "th" の返り値が .IR "thread_return" で指し示された領域に格納され、0 が返る。 エラーの場合、非 0 のエラーコードが返る。 .SH "エラー" .TP .B "ESRCH" .I "th" で指定された ID に対応するスレッドが見つからなかった。 .TP .B "EINVAL" .I "th" で指定されたスレッドはすでにデタッチされている。 .TP .B "EINVAL" すでに別のスレッドがスレッド .I "th" の終了を待っている。 .TP .B "EDEADLK" 引数 .I "th" が呼び出しスレッドを指している。 .SH "著者" Xavier Leroy .SH "関連項目" .BR "pthread_exit" (3), .BR "pthread_detach" (3), .BR "pthread_create" (3), .BR "pthread_attr_setdetachstate" (3), .BR "pthread_cleanup_push" (3), .BR "pthread_key_create" (3).