File: pthread_join.3

package info (click to toggle)
manpages-ja 0.5.0.0.20221215%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 29,304 kB
  • sloc: perl: 161; makefile: 61
file content (151 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
.\"   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 <pthread.h>

.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 <Xavier.Leroy@inria.fr>

.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).