OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / flockfile.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Japanese Version Copyright (c) 2001 Yuichi SATO
24 .\"         all rights reserved.
25 .\" Translated Sun Nov  4 14:09:45 2001
26 .\"         by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
27 .\"
28 .\"WORD:        lockcount       ¥í¥Ã¥¯¿ô
29 .\"WORD:        owner thread    ½êÍ­¼Ô¥¹¥ì¥Ã¥É
30 .\"
31 .TH FLOCKFILE 3  2008-08-29 "" "Linux Programmer's Manual"
32 .\"O .SH NAME
33 .\"O flockfile, ftrylockfile, funlockfile \- lock FILE for stdio
34 .SH Ì¾Á°
35 flockfile, ftrylockfile, funlockfile \- É¸½àÆþ½ÐÎÏ FILE ¤Î¥í¥Ã¥¯¤ò¹Ô¤¦
36 .\"O .SH SYNOPSIS
37 .SH ½ñ¼°
38 .nf
39 .B #include <stdio.h>
40 .sp
41 .BI "void flockfile(FILE *" filehandle );
42 .br
43 .BI "int ftrylockfile(FILE *" filehandle );
44 .br
45 .BI "void funlockfile(FILE *" filehandle );
46 .fi
47 .sp
48 .in -4n
49 .\"O Feature Test Macro Requirements for glibc (see
50 .\"O .BR feature_test_macros (7)):
51 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
52 .RB ( feature_test_macros (7)
53 »²¾È):
54 .in
55 .ad l
56 .sp
57 .\"O All functions shown above:
58 ¾åµ­¤ÎÁ´¤Æ¤Î´Ø¿ô:
59 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
60 _SVID_SOURCE || _POSIX_SOURCE
61 .ad b
62 .\"O .SH DESCRIPTION
63 .SH ÀâÌÀ
64 .\"O The stdio functions are thread-safe.
65 .\"O This is achieved by assigning
66 .\"O to each
67 .\"O .I FILE
68 .\"O object a lockcount and (if the lockcount is nonzero)
69 .\"O an owning thread.
70 ɸ½àÆþ½ÐÎÏ´Ø¿ô¤Ï¥¹¥ì¥Ã¥É¥»¡¼¥Õ¤Ç¤¢¤ë¡£¤³¤ì¤Ï¡¢³Æ
71 .I FILE
72 ¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¡¢¥í¥Ã¥¯¿ô (lockcount) ¤È
73 (¥í¥Ã¥¯¿ô¤¬ 0 ¤Ç¤Ê¤¤¾ì¹ç¤Ï) ½êÍ­¼Ô¥¹¥ì¥Ã¥É (owner thread)
74 ¤ò´ÉÍý¤¹¤ë¤³¤È¤Ç¼Â¸½¤µ¤ì¤ë¡£
75 .\"O For each library call, these functions wait until the
76 .\"O .I FILE
77 .\"O object
78 .\"O is no longer locked by a different thread, then lock it, do the
79 .\"O requested I/O, and unlock the object again.
80 ¥é¥¤¥Ö¥é¥ê¤Î¸Æ¤Ó½Ð¤·¤¬¹Ô¤ï¤ì¤ëËè¤Ë¡¢É¸½àÆþ½ÐÎÏ´Ø¿ô¤Ï
81 .I FILE
82 ¥ª¥Ö¥¸¥§¥¯¥È¤¬Â¾¤Î¥¹¥ì¥Ã¥É¤Ë¤è¤Ã¤Æ¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê¤¤¾õÂ֤ˤʤë¤Þ¤ÇÂÔ¤Á¡¢
83 .I FILE
84 ¥ª¥Ö¥¸¥§¥¯¥È¤ò¥í¥Ã¥¯¤·¡¢Í׵ᤵ¤ì¤ÆÆþ½ÐÎϤò¹Ô¤¤¡¢
85 ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë¡£
86 .LP
87 .\"O (Note: this locking has nothing to do with the file locking done
88 .\"O by functions like
89 .\"O .BR flock (2)
90 .\"O and
91 .\"O .BR lockf (3).)
92 (Ãí: ¤³¤Î¥í¥Ã¥¯¤Ï¡¢
93 .BR flock (2)
94 ¤ä
95 .BR lockf (3)
96 ¤È¤¤¤Ã¤¿´Ø¿ô¤¬¹Ô¤¦¥í¥Ã¥¯¤È¤ÏÁ´¤¯Ìµ´Ø·¸¤Ç¤¢¤ë¡£)
97 .LP
98 .\"O All this is invisible to the C-programmer, but there may be two
99 .\"O reasons to wish for more detailed control.
100 .\"O On the one hand, maybe
101 .\"O a series of I/O actions by one thread belongs together, and should
102 .\"O not be interrupted by the I/O of some other thread.
103 .\"O On the other hand, maybe the locking overhead should be avoided
104 .\"O for greater efficiency.
105 ¤³¤ì¤é¤Î¤³¤È¤Ï¤¹¤Ù¤Æ C ¥×¥í¥°¥é¥Þ¤Ë¤Ï¸«¤¨¤Ê¤¤Éôʬ¤Ç¹Ô¤ï¤ì¤ë¤¬¡¢
106 ¤è¤êºÙ¤«¤¤À©¸æ¤¬¤Ç¤­¤¿Êý¤¬¤è¤¤Íýͳ¤¬2¤Ä¤¢¤ë¤À¤í¤¦¡£°ì¤Ä¤Ï¡¢°ì¤Ä¤Î¥¹¥ì¥Ã¥É¤¬
107 ¹Ô¤¦°ìÏ¢¤ÎÆþ½ÐÎÏÆ°ºî¤Ï°ì½ï¤Ë¹Ô¤ï¤ì¡¢Â¾¤Î¥¹¥ì¥Ã¥É¤ÎÆþ½ÐÎϤˤè¤Ã¤ÆÃæÃǤµ¤ì¤Ê¤¤
108 Êý¤¬¤è¤¤¤È¤¤¤¦¤³¤È¤Ç¤¢¤í¤¦¡£¤â¤¦°ì¤Ä¤Ï¡¢¸úΨ¤òÂ礭¤¯¾å¤²¤ë¤¿¤á¤Ë¤Ï
109 ¥í¥Ã¥¯¤Î¥ª¡¼¥Ð¥Ø¥Ã¥É¤òÈò¤±¤ëɬÍפ¬¤¢¤ë¤È¤¤¤¦¤³¤È¤Ç¤¢¤í¤¦¡£
110 .LP
111 .\"O To this end, a thread can explicitly lock the
112 .\"O .I FILE
113 .\"O object,
114 .\"O then do its series of I/O actions, then unlock.
115 .\"O This prevents
116 .\"O other threads from coming in between.
117 .\"O If the reason for doing
118 .\"O this was to achieve greater efficiency, one does the I/O with
119 .\"O the nonlocking versions of the stdio functions: with
120 .\"O .BR getc_unlocked (3)
121 .\"O and
122 .\"O .BR putc_unlocked (3)
123 .\"O instead of
124 .\"O .BR getc (3)
125 .\"O and
126 .\"O .BR putc (3).
127 ¤³¤ÎÌÜŪ¤ò¼Â¸½¤¹¤ë¤¿¤á¤Ë¡¢
128 .I FILE
129 ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥í¥Ã¥¯¡¢°ìÏ¢¤ÎÆþ½ÐÎÏÆ°ºî¤Î¼Â¹Ô¡¢
130 ¥í¥Ã¥¯¤Î²ò½ü¤ò¥¹¥ì¥Ã¥É¤¬ÌÀ¼¨Åª¤Ë»Ø¼¨¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
131 ¤³¤ì¤Ë¤è¤ê¡¢Â¾¤Î¥¹¥ì¥Ã¥É¤¬ÅÓÃæ¤ÇÆþ½ÐÎϤò¹Ô¤¦¤Î¤òËɻߤ¹¤ë¡£
132 ¤³¤Î¤è¤¦¤Ê¤³¤È¤ò¹Ô¤¦Íýͳ¤¬¸úΨ¤Î¸þ¾å¤Ç¤¢¤ë¤Ê¤é¤Ð¡¢
133 ¥í¥Ã¥¯¤ò¹Ô¤ï¤Ê¤¤¥Ð¡¼¥¸¥ç¥ó¤Îɸ½àÆþ½ÐÎÏ´Ø¿ô¤ò»È¤¦¤³¤È¤â¤Ç¤­¤ë¡£
134 Î㤨¤Ð¡¢
135 .BR getc (3)
136 ¤ä
137 .BR putc (3)
138 ¤ÎÂå¤ï¤ê¤Ë
139 .BR getc_unlocked (3)
140 ¤ä
141 .BR putc_unlocked (3)
142 ¤ò»ÈÍѤ¹¤ë¡£
143 .LP
144 .\"O The
145 .\"O .BR flockfile ()
146 .\"O function waits for \fI*filehandle\fP to be
147 .\"O no longer locked by a different thread, then makes the
148 .\"O current thread owner of \fI*filehandle\fP, and increments
149 .\"O the lockcount.
150 .BR flockfile ()
151 ´Ø¿ô¤Ï¡¢\fI*filehandle\fP ¤¬Â¾¤Î¥¹¥ì¥Ã¥É¤Ë¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê
152 ¤¤¾õÂ֤ˤʤë¤Þ¤ÇÂԤ俤ΤÁ¡¢¸½ºß¤Î¥¹¥ì¥Ã¥É¤ò \fI*filehandle\fP ¤Î¥ª¡¼¥Ê¤ËÀß
153 Äꤷ¡¢¥í¥Ã¥¯¿ô¤ò²Ã»»¤¹¤ë¡£
154 .LP
155 .\"O The
156 .\"O .BR funlockfile ()
157 .\"O function decrements the lock count.
158 .BR funlockfile ()
159 ´Ø¿ô¤Ï¡¢¥í¥Ã¥¯¿ô¤ò¸º»»¤¹¤ë¡£
160 .LP
161 .\"O The
162 .\"O .BR ftrylockfile ()
163 .\"O function is a nonblocking version
164 .\"O of
165 .\"O .BR flockfile ().
166 .\"O It does nothing in case some other thread
167 .\"O owns \fI*filehandle\fP, and it obtains ownership and increments
168 .\"O the lockcount otherwise.
169 .BR ftrylockfile ()
170 ´Ø¿ô¤Ï
171 .BR flockfile ()
172 ¤Î¥Ö¥í¥Ã¥­¥ó¥°¤ò¹Ô¤ï¤Ê¤¤
173 ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¡£Â¾¤Î¥¹¥ì¥Ã¥É¤¬ \fI*filehandle\fP ¤ò¥í¥Ã¥¯¤·¤Æ¤¤¤ë»þ¤Ï
174 ²¿¤â¹Ô¤ï¤º¡¢¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï \fI*filehandle\fP ¤Î½êÍ­¸¢¤ò³ÍÆÀ¤·¡¢
175 ¥í¥Ã¥¯¿ô¤ò²Ã»»¤¹¤ë¡£
176 .\"O .SH "RETURN VALUE"
177 .SH ÊÖ¤êÃÍ
178 .\"O The
179 .\"O .BR ftrylockfile ()
180 .\"O function returns zero for success
181 .\"O (the lock was obtained), and nonzero for failure.
182 .BR ftrylockfile ()
183 ´Ø¿ô¤Ï¥í¥Ã¥¯¤ËÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢
184 ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï 0 °Ê³°¤ÎÃͤòÊÖ¤¹¡£
185 .\"O .SH ERRORS
186 .\"O None.
187 .SH ¥¨¥é¡¼
188 ¤Ê¤·¡£
189 .\"O .SH "CONFORMING TO"
190 .SH ½àµò
191 POSIX.1-2001.
192 .\"O .SH AVAILABILITY
193 .SH ²ÄÍÑÀ­
194 .\"O These functions are available when
195 .\"O .B _POSIX_THREAD_SAFE_FUNCTIONS
196 .\"O is defined.
197 .\"O They are in libc since libc 5.1.1 and in glibc
198 .\"O since glibc 2.0.
199 .B _POSIX_THREAD_SAFE_FUNCTIONS
200 ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤È¤­¤Ë¤³¤ì¤é¤Î´Ø¿ô¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
201 5.1.1 °Ê¹ß¤Î libc ¤È 2.0 °Ê¹ß¤Î glibc ¤Ë¸ºß¤¹¤ë¡£
202 .\"O .SH "SEE ALSO"
203 .SH ´ØÏ¢¹àÌÜ
204 .BR unlocked_stdio (3)