File: pthread_key_create.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 (248 lines) | stat: -rw-r--r-- 6,016 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
.\"   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 23:11:09 JST 2002
.\"         by Suzuki Takashi.
.\"
.\"WORD:    thread-specific data    åɸͭǡ
.\"WORD:    thread-specific key åɸͭ
.\"WORD:    destructor function ǥȥ饯ؿ
.\"
.\"
.TH PTHREAD_SPECIFIC 3 LinuxThreads

.SH "̾"
pthread_key_create, pthread_key_delete, pthread_setspecific, pthread_getspecific \- åɸͭǡδ

.SH ""
.B #include <pthread.h>

.BI "int pthread_key_create(pthread_key_t *" key ", void (*" destr_function ") (void *));"

.BI "int pthread_key_delete(pthread_key_t " key ");"

.BI "int pthread_setspecific(pthread_key_t " key ", const void *" pointer ");"

.BI "void * pthread_getspecific(pthread_key_t " key ");"

.SH ""

ץǤϥåɤȤͤΰۤʤ
ХѿŪѿФɬפȤʤ롣
ʣΥåɤ 1 ĤΥ֤ͭ뤿ᡢ
̾ѿǤϤ¸뤳ȤǤʤ
åɸͭǡϡ
ɬؤ POSIX åɤǤ롣

줾Υåɤϥåɸͭǡ (thread-specific data) ΰ衢
ά TSD ΰȤ
ץ饤١Ȥʥ֥åͭƤ롣
ΰ TSD 򥤥ǥåȤƴ롣
TSD ΰǤ
.B "void *"
ͤ TSD ˷դ롣
TSD Ϥ٤ƤΥåɤ˶̤Ǥ뤬
TSD ˷դͤϥåɤȤ˰ۤʤ褦
뤳ȤǤ롣

ŪˤС TSD ΰ
.B "void *"
Υݥ󥿤Ȥơ
TSD ϤФͤΥǥåȤơ
TSD ˷դͤϸƤӽФåɤбǤȤƸ롣

åɤȡTSD ΰϤ٤ƤΥФͤ
.B "NULL"
ˤʤ褦롣

.B "pthread_key_create"
Ͽ TSD ݤ롣

.I "key"
ǻؤΰ˳Ǽ롣
dzݤǤ륭οˤ¤ꡢ
κͤ
.B "PTHREAD_KEYS_MAX"
Ǥ롣
֤줿˷դͤϡ
λǼ¹ԤƤ륹åɤ٤Ƥˤ
.B "NULL"
Ǥ롣


.I "destr_function"

.B "NULL"
ʳͤꤹ뤳Ȥǡ
Υбǥȥ饯ؿϿ뤳ȤǤ롣
åɤ
.B "pthread_exit"
䥭󥻥ˤäƽλȡ
Υåǥ˷դ줿ͤȤƴؿ
.I "destr_function"
ƤӽФ롣
ͤ
.B "NULL"
ξˤϴؿ
.I "destr_function"
ϸƤӽФʤ
åɽλ˥ǥȥ饯ؿƤӽФǤ롣

ǥȥ饯ؿƤӽФˡ
ߤΥåɤˤƥ˷դͤ
.B "NULL"
ˤʤ롣
ǥȥ饯ؿ
.B "NULL"
ʳͤ򤽤ΥۤΥ˷դ뤫⤷ʤ
뤿ᡢ
٤Ƥ
.B "NULL"
ͤФǥȥ饯ؿ򤹤٤ƸƤӽФȤ
ǥȥ饯ؿΤ
.B "NULL"
ͤޤĤäƤˤϡ
ǥȥ饯ؿθƤӽФϷ֤롣
LinuxThreads μǤϡ
.B "PTHREAD_DESTRUCTOR_ITERATIONS"
󷫤֤ȡȤǥȥ饯ؿΤ
.B "NULL"
ͤĤäƤƤ⡢
ߤ롣LinuxThreads ʳμǤ̵¥롼פ˴٤뤫⤷ʤ

.B "pthread_key_delete"
 TSD 롣
λǼ¹Υåɤǥ
.B "NULL"
ͤդƤ뤫ɤåꡢ
бǥȥ饯ؿƤӽФϤʤ

.B "pthread_setspecific"
ϸƤӽФåɤ
.I "key"
˷դͤͿ줿
.I "pointer"
ѹ롣

.B "pthread_getspecific"
ϸƤӽФåɤǤλ
.I "key"
˷դƤ֤ͤ

.SH "֤"

.B "pthread_key_create"

.B "pthread_key_delete"

.B "pthread_setspecific"
 0 򡢼Ԥ 0 Υ顼ɤ֤
ξ硢
.B "pthread_key_create"
Ͽݤ줿

.I "key"
ǻؤΰ˳Ǽ롣

.B "pthread_getspecific"
ϡȥ
.I "key"
˷դ줿ͤ
顼ξˤ
.B "NULL"
֤

.SH "顼"
.B "pthread_key_create"
ϥ顼ξ˼Τ褦ʥ顼ɤ֤:
.RS
.TP
.B "EAGAIN"
.B "PTHREAD_KEYS_MAX"
ΥǤ˳ݤƤ롣
.RE

.B "pthread_key_delete"
 
.B "pthread_setspecific"
ϥ顼ξ˼Τ褦ʥ顼ɤ֤:
.RS
.TP
.B "EINVAL"
.I "key"
ͭʡݤ줿 TSD ǤϤʤ
.RE

.B "pthread_getspecific"
ϡ
.I "key"
ͭʡݤ줿 TSD Ǥʤˤ
.B "NULL"
֤

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

.SH "Ϣ"
pthread_create(3), pthread_exit(3), pthread_testcancel(3).

.SH ""

ΥɤǤϡ100 ХȤΥåɸͭݤ
åɤνλȤȤ˼ưDz:

.RS
.ft 3
.nf
.sp
/* åɸͭХåեΥ */
static pthread_key_t buffer_key;

/* 1 ¤Υν */
static pthread_once_t buffer_key_once = PTHREAD_ONCE_INIT;

/* åɸͭΥХåեݤ */
void buffer_alloc(void)
{
  pthread_once(&buffer_key_once, buffer_key_alloc);
  pthread_setspecific(buffer_key, malloc(100));
}

/* åɸͭΥХåե֤ */
char * get_buffer(void)
{
  return (char *) pthread_getspecific(buffer_key);
}

/* ݤ */
static void buffer_key_alloc()
{
  pthread_key_create(&buffer_key, buffer_destroy);
}

/* åɸͭΥХåե */
static void buffer_destroy(void * buf)
{
  free(buf);
}
.ft
.LP
.RE
.fi