.\" 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_EXIT 3 2014\-05\-23 Linux "Linux Programmer's Manual" .SH 名前 pthread_exit \- 呼び出したスレッドを終了する .SH 書式 .nf \fB#include \fP \fBvoid pthread_exit(void *\fP\fIretval\fP\fB);\fP .sp \fI\-pthread\fP でコンパイルしてリンクする。 .fi .SH 説明 \fBpthread_exit\fP() 関数は、呼び出したスレッドを終了し、 \fIretval\fP 経由で値を返す。 この値は (そのスレッドが join 可能な場合に) \fBpthread_join\fP(3) を 呼び出した同じプロセス内の別のスレッドが参照できる値と同じである。 \fBpthread_cleanup_push\fP(3) で設定されたクリーンアップハンドラーのうち、 まだ pop (取り出されていない) ハンドラーを (push されたのと逆の順序で) 取り出して実行する。そのスレッドがスレッド固有のデータを持っている 場合は、クリーンアップハンドラーが実行された後に、スレッド固有のデータ に対応するデストラクタ (destructor) 関数が呼び出される (呼び出し順序 は規定されていない)。 スレッドが終了する際に、プロセスの共有リソース (例えば、mutex、状態変数 (condition variables)、セマフォ、ファイルディスクリプター)が解放される。 \fBatexit\fP(3) を使って登録された関数は呼び出されない。 プロセスの最後のスレッドが終了すると、そのプロセスは、終了ステータス 0 で \fBexit\fP(3) を呼び出した場合と全く同じように終了する。したがって、 プロセスの共有リソースは解放され、\fBatexit\fP(3) を使って登録された関数 が呼び出される。 .SH 返り値 この関数は呼び出し側には返らない。 .SH エラー この関数は常に成功する。 .SH 属性 .SS "マルチスレッディング (pthreads(7) 参照)" \fBpthread_exit\fP() 関数はスレッドセーフである。 .SH 準拠 POSIX.1\-2001. .SH 注意 メインスレッド以外のスレッドの開始関数 (start function) がreturn を 行うと、暗黙のうちに \fBpthread_exit\fP() が呼び出され、 関数の返り値がスレッドの終了ステータスとして使用される。 他のスレッドが実行を継続できるように、メインスレッドは \fBexit\fP(3) では なく \fBpthread_exit\fP() を呼び出して終了すべきである。 \fIretval\fP が指す値は、呼び出したスレッドのスタックに置くべきではない。 呼び出したスレッドが終了した後は、そのスタックの内容が不定となるから である。 .SH バグ .\" Linux 2.6.27 .\" FIXME . review a later kernel to see if this gets fixed .\" http://thread.gmane.org/gmane.linux.kernel/611611 .\" http://marc.info/?l=linux-kernel&m=122525468300823&w=2 現在のところ、停止 (stop) されたスレッドグループを、すでに終了した (dead) スレッドグループリーダーで \fBwait\fP(2) する場合の、 カーネル実装の論理には制限がある。 この制限は、すでにスレッドグループリーダーが \fBpthread_exit\fP() を 呼び出しているようなフォアグラウンドプロセスにストップシグナルが送信 された場合に、端末がロックされてしまう、といった問題として表に見える 場合がある。 .SH 関連項目 \fBpthread_create\fP(3), \fBpthread_join\fP(3), \fBpthreads\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。