pthread_detachのヘルプ・マニュアル
日本語 英語
pthread_detach --help
man pthread_detach
PTHREAD_DETACH(3) PTHREAD_DETACH(3)
名前
pthread_detach - 実行中のスレッドをデタッチ状態にする
書式
#include
int pthread_detach(pthread_t th);
説明
pthread_detach はスレッド th をデタッチ状態にする。これは th が終了した
ときに、 th によって消費されていたメモリ資源を即座に解放することを保 証
する。しかしながら、これによって他のスレッドは pthread_join を用いて th
の終了に同期することができなくなる。
スレッドは pthread_create(3) の属性に detachstate を用いることによっ て
、 最 初 か ら デ タ ッ チ 状 態 で 生 成することができる。これに対し、
pthread_detach は合流可能状態として生成され、後にデタッチ状態にする必要
の出てきたスレッドに適用される。
pthread_detach が完了した後、 th に対して pthread_join を実行しても失敗
する。もし pthread_detach が呼ばれた時に別のスレッドがスレッド th の 終
了を待っている (joining) ならば、 pthread_detach は何もせず、 th を合流
可能状態のままにしておく。
返り値
成功すると 0 が返る。エラーの場合は、非 0 のエラーコードが返る。
エラー
ESRCH th で指定したスレッドが見つからない。
EINVAL スレッド th は既にデタッチ状態にある。
著者 Xavier Leroy
関連項目
pthread_create(3), pthread_join(3), pthread_attr_setdetachstate(3)
LinuxThreads PTHREAD_DETACH(3)
PTHREAD_DETACH(3) Linux Programmer’s Manual PTHREAD_DETACH(3)
NAME
pthread_detach - detach a thread
SYNOPSIS
#include
int pthread_detach(pthread_t thread);
Compile and link with -pthread.
DESCRIPTION
The pthread_detach() function marks the thread identified by thread as
detached. When a detached thread terminates, its resources are auto-
matically released back to the system without the need for another
thread to join with the terminated thread.
Attempting to detach an already detached thread results in unspecified
behavior.
RETURN VALUE
On success, pthread_detach() returns 0; on error, it returns an error
number.
ERRORS
EINVAL thread is not a joinable thread.
ESRCH No thread with the ID thread could be found.
CONFORMING TO
POSIX.1-2001.
NOTES
Once a thread has been detached, it can’t be joined with
pthread_join(3) or be made joinable again.
A new thread can be created in a detached state using pthread_attr_set-
detachstate(3) to set the detached attribute of the attr argument of
pthread_create(3).
The detached attribute merely determines the behavior of the system
when the thread terminates; it does not prevent the thread from being
terminated if the process terminates using exit(3) (or equivalently, if
the main thread returns).
Either pthread_join(3) or pthread_detach() should be called for each
thread that an application creates, so that system resources for the
thread can be released. (But note that the resources of all threads
are freed when the process terminates.)
EXAMPLE
The following statement detaches the calling thread:
pthread_detach(pthread_self());
SEE ALSO
pthread_attr_setdetachstate(3), pthread_cancel(3), pthread_create(3),
pthread_exit(3), pthread_join(3), pthreads(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-11-27 PTHREAD_DETACH(3)