File: pthread_cleanup_push.3

package info (click to toggle)
manpages-ja 0.5.0.0.20061115-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 19,788 kB
  • ctags: 4
  • sloc: sh: 13,215; perl: 157; makefile: 117
file content (304 lines) | stat: -rw-r--r-- 7,030 bytes parent folder | download | duplicates (4)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
.\"   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 21:07:33 JST 2002
.\"         by Suzuki Takashi.
.\"
.\"WORD:    cleanup handler     ꡼󥢥åץϥɥ
.\"WORD:    cancellation        ä
.\"WORD:    stack-like          å
.\"WORD:    non-portable extension  ݡ֥Ǥʤĥ
.\"WORD:    cancellation type   ä
.\"WORD:    deferred            ʼäΡٱ
.\"WORD:    asynchronous        ʼäΡƱ
.\"WORD:    cancellation mode   ä
.\"
.\"
.TH PTHREAD_CLEANUP 3 LinuxThreads


.SH ̾
pthread_cleanup_push, pthread_cleanup_pop, pthread_cleanup_push_defer_np, pthread_cleanup_pop_restore_np 
\- ꡼󥢥åץϥɥϿӺ

.SH 
.B #include <pthread.h>

.BI "void pthread_cleanup_push(void (*" routine ") (void *), void *" arg ");"

.BI "void pthread_cleanup_pop(int " execute ");"

.BI "void pthread_cleanup_push_defer_np(void (*" routine ") (void *), void *" arg ");"

.BI "void pthread_cleanup_pop_restore_np(int " execute ");"

.SH ""

꡼󥢥åץϥɥϡ
.BR "pthread_exit" (3)
ƤӽФ줿ꡢä줿ꤷ
åɤλȤ˸ƤӽФؿǤ롣
꡼󥢥åץϥɥ
åε§ˤʤäϿӺ롣

꡼󥢥åץϥɥŪϡ
åɤλȤݻƤ뤫⤷ʤ񸻤
뤳ȤǤ롣
ˡåɤå mutex ݻޤ
λä줿ꤹȡ
 mutex ϱʵפ˥å줿ޤޤǡ
ۤΥåɤ˼¹ԤǤʤʤäƤޤ
ΤȤɤǤ褤ˡϡ
mutex åľˡ
mutex Υå뤿
꡼󥢥åץϥɥϿ뤳ȤǤ롣
Ʊ褦ˡ꡼󥢥åץϥɥ
åɤνλ
.BR "malloc" (3)
dzݤ줿֥å
եǥץ򥯥ꤹΤ˻ѤǤ롣

.B "pthread_cleanup_push"
ϴؿ
.I "routine"

.I "arg"
ȤȤ˥꡼󥢥åץϥɥȤϿ롣
λ
б
.B "pthread_cleanup_pop"
ޤǤδ֡
Υåɤ
.BR "pthread_exit" (3)
ޤϼäˤäƽλˡ
ؿ
.I "routine"

.I "arg"
ȤʤäƸƤӽФ褦ˤʤ롣
λʣΥ꡼󥢥åץϥɥ餬ͭˤʤäƤϡ
꡼󥢥åץϥɥ LIFO ˸ƤӽФ:
ʤǸϿ줿ϥɥ餬ǽ˸ƤӽФ롣

.B "pthread_cleanup_pop"
ϡǸϿ줿꡼󥢥åץϥɥ롣

.I "execute"
 0 Ǥʤ硢
.B "pthread_cleanup_pop"
ϥϥɥ¹Ԥ롣
ʤ
ؿ
.I "routine"

.I "arg"
ȤʤäƸƤӽФ

.I "execute"
 0 ξϡϥɥ餬ǡ¹Ԥ뤳ȤϤʤ

б
.B "pthread_cleanup_push"

.B "pthread_cleanup_pop"
ФϡƱؿΡ
Ʊ֥åؤˤʤФʤʤ
ºݡ
.B "pthread_cleanup_push"

.B "pthread_cleanup_pop"
ϥޥǤꡢ
.B "pthread_cleanup_push"
ΥޥŸˤ

.B "{"
ޤޤƤơб
Ĥ
.B "}"
ϡб
.B "pthread_cleanup_pop"
ΥޥŸ˴ޤޤƤ롣

.B "pthread_cleanup_push_defer_np"
ϡ
.B "pthread_cleanup_push"

.BR "pthread_setcanceltype" (3)
Ȥ߹碌ݡ֥ǤʤĥǤ롣
.B "pthread_cleanup_push"
ȤޤäƱ褦˥꡼󥢥åץϥɥϿ뤬
Ʊˤλμä¸
äٱ (deferred) ѹ롣
ˤäơ
åɤμäƱ (asynchronous) ǤäƤ
꡼󥢥å׵ͭˤʤ뤳Ȥݾڤ롣

.B "pthread_cleanup_pop_restore_np"

.B "pthread_cleanup_push_defer_np"
ˤäϿ줿ϥ꡼󥢥åץϥɥ
ä
.B "pthread_cleanup_push_defer_np"
ƤӽФ줿᤹ͤ

.B "pthread_cleanup_push_defer_np"

.B "pthread_cleanup_pop_restore_np"
ФˤʤäƤʤФʤ餺
ȤƱ֥åؤˤʤФʤʤ


.RS
.ft 3
.nf
.sp
pthread_cleanup_push_defer_np(routine, arg);
...
pthread_cleanup_pop_defer_np(execute);
.ft
.LP
.RE
.fi

Τ褦ήϵǽŪ˼ΤΤƱ (ꥳѥȤǤΨŪ) Ǥ롣

.RS
.ft 3
.nf
.sp
{ int oldtype;
  pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
  pthread_cleanup_push(routine, arg);
  ...
  pthread_cleanup_pop(execute);
  pthread_setcanceltype(oldtype, NULL);
}
.ft
.LP
.RE
.fi

.SH "֤"

ʤ

.SH "顼"

ʤ

.SH ""
Xavier Leroy <Xavier.Leroy@inria.fr>

.SH "Ϣ"
.BR "pthread_exit" (3),
.BR "pthread_cancel" (3),
.BR "pthread_setcanceltype" (3).

.SH ""

ϡ mutex
.I "mut"
å˥åɤä줿
å褦ˡ
mutex
.I "mut"
åˡǤ: 

.RS
.ft 3
.nf
.sp
pthread_cleanup_push(pthread_mutex_unlock, (void *) &mut);
pthread_mutex_lock(&mut);
/* 򤹤 */
pthread_mutex_unlock(&mut);
pthread_cleanup_pop(0);
.ft
.LP
.RE
.fi

Ǹ 2 ԤϼΤΤƱǡ֤ǽǤ: 

.RS
.ft 3
.nf
.sp
pthread_cleanup_pop(1);
.ft
.LP
.RE
.fi

Υɤϼäٱ (deferred) Ǥ˸¤ä
Ǥ뤳Ȥդ뤳 (
.BR "pthread_setcanceltype" (3)
򻲾 ) 
äƱ (asynchronous) ξˤϡ
åɤμä
.B "pthread_cleanup_push"

.B "pthread_mutex_lock"
δ֤䡢
.B "pthread_mutex_unlock"

.B "pthread_cleanup_pop"
δ֤ǵǽꡢ
ɤξˤ⥹åɤϥȥåɤ
åƤʤ mutex å褦ȤƤޤ
ΤȤƱäȤˤȤμͳǤ롣

ΥɤƱäǤưʤФʤʤ硢
mutex ΥåӥåΤˡ
äٱ (deferred) ѹʤФʤʤ:

.RS
.ft 3
.nf
.sp
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldtype);
pthread_cleanup_push(pthread_mutex_unlock, (void *) &mut);
pthread_mutex_lock(&mut);
/* do some work */
pthread_cleanup_pop(1);
pthread_setcanceltype(oldtype, NULL);
.ft
.LP
.RE
.fi

Υɤϡݡ֥Ǥʤؿ
.B "pthread_cleanup_push_defer_np"

.B "pthread_cleanup_pop_restore_np"
ȤȤǡꥳѥȤǤΨŪˡ˽ľȤǤ:

.RS
.ft 3
.nf
.sp
pthread_cleanup_push_restore_np(pthread_mutex_unlock, (void *) &mut);
pthread_mutex_lock(&mut);
/* do some work */
pthread_cleanup_pop_restore_np(1);
.ft
.LP
.RE
.fi