OSDN Git Service

(split) LDP_man-pages: release ioctl.2 [JM:00378]
[linuxjm/LDP_man-pages.git] / 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 .RS 4
60 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
61 _SVID_SOURCE || _POSIX_SOURCE
62 .RE
63 .ad b
64 .\"O .SH DESCRIPTION
65 .SH ÀâÌÀ
66 .\"O The stdio functions are thread-safe.
67 .\"O This is achieved by assigning
68 .\"O to each
69 .\"O .I FILE
70 .\"O object a lockcount and (if the lockcount is nonzero)
71 .\"O an owning thread.
72 ɸ½àÆþ½ÐÎÏ´Ø¿ô¤Ï¥¹¥ì¥Ã¥É¥»¡¼¥Õ¤Ç¤¢¤ë¡£¤³¤ì¤Ï¡¢³Æ
73 .I FILE
74 ¥ª¥Ö¥¸¥§¥¯¥È¤ËÂФ·¡¢¥í¥Ã¥¯¿ô (lockcount) ¤È
75 (¥í¥Ã¥¯¿ô¤¬ 0 ¤Ç¤Ê¤¤¾ì¹ç¤Ï) ½êÍ­¼Ô¥¹¥ì¥Ã¥É (owner thread)
76 ¤ò´ÉÍý¤¹¤ë¤³¤È¤Ç¼Â¸½¤µ¤ì¤ë¡£
77 .\"O For each library call, these functions wait until the
78 .\"O .I FILE
79 .\"O object
80 .\"O is no longer locked by a different thread, then lock it, do the
81 .\"O requested I/O, and unlock the object again.
82 ¥é¥¤¥Ö¥é¥ê¤Î¸Æ¤Ó½Ð¤·¤¬¹Ô¤ï¤ì¤ëËè¤Ë¡¢É¸½àÆþ½ÐÎÏ´Ø¿ô¤Ï
83 .I FILE
84 ¥ª¥Ö¥¸¥§¥¯¥È¤¬Â¾¤Î¥¹¥ì¥Ã¥É¤Ë¤è¤Ã¤Æ¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê¤¤¾õÂ֤ˤʤë¤Þ¤ÇÂÔ¤Á¡¢
85 .I FILE
86 ¥ª¥Ö¥¸¥§¥¯¥È¤ò¥í¥Ã¥¯¤·¡¢Í׵ᤵ¤ì¤ÆÆþ½ÐÎϤò¹Ô¤¤¡¢
87 ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥í¥Ã¥¯¤ò²ò½ü¤¹¤ë¡£
88 .LP
89 .\"O (Note: this locking has nothing to do with the file locking done
90 .\"O by functions like
91 .\"O .BR flock (2)
92 .\"O and
93 .\"O .BR lockf (3).)
94 (Ãí: ¤³¤Î¥í¥Ã¥¯¤Ï¡¢
95 .BR flock (2)
96 ¤ä
97 .BR lockf (3)
98 ¤È¤¤¤Ã¤¿´Ø¿ô¤¬¹Ô¤¦¥í¥Ã¥¯¤È¤ÏÁ´¤¯Ìµ´Ø·¸¤Ç¤¢¤ë¡£)
99 .LP
100 .\"O All this is invisible to the C-programmer, but there may be two
101 .\"O reasons to wish for more detailed control.
102 .\"O On the one hand, maybe
103 .\"O a series of I/O actions by one thread belongs together, and should
104 .\"O not be interrupted by the I/O of some other thread.
105 .\"O On the other hand, maybe the locking overhead should be avoided
106 .\"O for greater efficiency.
107 ¤³¤ì¤é¤Î¤³¤È¤Ï¤¹¤Ù¤Æ C ¥×¥í¥°¥é¥Þ¤Ë¤Ï¸«¤¨¤Ê¤¤Éôʬ¤Ç¹Ô¤ï¤ì¤ë¤¬¡¢
108 ¤è¤êºÙ¤«¤¤À©¸æ¤¬¤Ç¤­¤¿Êý¤¬¤è¤¤Íýͳ¤¬2¤Ä¤¢¤ë¤À¤í¤¦¡£°ì¤Ä¤Ï¡¢°ì¤Ä¤Î¥¹¥ì¥Ã¥É¤¬
109 ¹Ô¤¦°ìÏ¢¤ÎÆþ½ÐÎÏÆ°ºî¤Ï°ì½ï¤Ë¹Ô¤ï¤ì¡¢Â¾¤Î¥¹¥ì¥Ã¥É¤ÎÆþ½ÐÎϤˤè¤Ã¤ÆÃæÃǤµ¤ì¤Ê¤¤
110 Êý¤¬¤è¤¤¤È¤¤¤¦¤³¤È¤Ç¤¢¤í¤¦¡£¤â¤¦°ì¤Ä¤Ï¡¢¸úΨ¤òÂ礭¤¯¾å¤²¤ë¤¿¤á¤Ë¤Ï
111 ¥í¥Ã¥¯¤Î¥ª¡¼¥Ð¥Ø¥Ã¥É¤òÈò¤±¤ëɬÍפ¬¤¢¤ë¤È¤¤¤¦¤³¤È¤Ç¤¢¤í¤¦¡£
112 .LP
113 .\"O To this end, a thread can explicitly lock the
114 .\"O .I FILE
115 .\"O object,
116 .\"O then do its series of I/O actions, then unlock.
117 .\"O This prevents
118 .\"O other threads from coming in between.
119 .\"O If the reason for doing
120 .\"O this was to achieve greater efficiency, one does the I/O with
121 .\"O the nonlocking versions of the stdio functions: with
122 .\"O .BR getc_unlocked (3)
123 .\"O and
124 .\"O .BR putc_unlocked (3)
125 .\"O instead of
126 .\"O .BR getc (3)
127 .\"O and
128 .\"O .BR putc (3).
129 ¤³¤ÎÌÜŪ¤ò¼Â¸½¤¹¤ë¤¿¤á¤Ë¡¢
130 .I FILE
131 ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥í¥Ã¥¯¡¢°ìÏ¢¤ÎÆþ½ÐÎÏÆ°ºî¤Î¼Â¹Ô¡¢
132 ¥í¥Ã¥¯¤Î²ò½ü¤ò¥¹¥ì¥Ã¥É¤¬ÌÀ¼¨Åª¤Ë»Ø¼¨¤¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
133 ¤³¤ì¤Ë¤è¤ê¡¢Â¾¤Î¥¹¥ì¥Ã¥É¤¬ÅÓÃæ¤ÇÆþ½ÐÎϤò¹Ô¤¦¤Î¤òËɻߤ¹¤ë¡£
134 ¤³¤Î¤è¤¦¤Ê¤³¤È¤ò¹Ô¤¦Íýͳ¤¬¸úΨ¤Î¸þ¾å¤Ç¤¢¤ë¤Ê¤é¤Ð¡¢
135 ¥í¥Ã¥¯¤ò¹Ô¤ï¤Ê¤¤¥Ð¡¼¥¸¥ç¥ó¤Îɸ½àÆþ½ÐÎÏ´Ø¿ô¤ò»È¤¦¤³¤È¤â¤Ç¤­¤ë¡£
136 Î㤨¤Ð¡¢
137 .BR getc (3)
138 ¤ä
139 .BR putc (3)
140 ¤ÎÂå¤ï¤ê¤Ë
141 .BR getc_unlocked (3)
142 ¤ä
143 .BR putc_unlocked (3)
144 ¤ò»ÈÍѤ¹¤ë¡£
145 .LP
146 .\"O The
147 .\"O .BR flockfile ()
148 .\"O function waits for \fI*filehandle\fP to be
149 .\"O no longer locked by a different thread, then makes the
150 .\"O current thread owner of \fI*filehandle\fP, and increments
151 .\"O the lockcount.
152 .BR flockfile ()
153 ´Ø¿ô¤Ï¡¢\fI*filehandle\fP ¤¬Â¾¤Î¥¹¥ì¥Ã¥É¤Ë¥í¥Ã¥¯¤µ¤ì¤Æ¤¤¤Ê
154 ¤¤¾õÂ֤ˤʤë¤Þ¤ÇÂԤ俤ΤÁ¡¢¸½ºß¤Î¥¹¥ì¥Ã¥É¤ò \fI*filehandle\fP ¤Î¥ª¡¼¥Ê¤ËÀß
155 Äꤷ¡¢¥í¥Ã¥¯¿ô¤ò²Ã»»¤¹¤ë¡£
156 .LP
157 .\"O The
158 .\"O .BR funlockfile ()
159 .\"O function decrements the lock count.
160 .BR funlockfile ()
161 ´Ø¿ô¤Ï¡¢¥í¥Ã¥¯¿ô¤ò¸º»»¤¹¤ë¡£
162 .LP
163 .\"O The
164 .\"O .BR ftrylockfile ()
165 .\"O function is a nonblocking version
166 .\"O of
167 .\"O .BR flockfile ().
168 .\"O It does nothing in case some other thread
169 .\"O owns \fI*filehandle\fP, and it obtains ownership and increments
170 .\"O the lockcount otherwise.
171 .BR ftrylockfile ()
172 ´Ø¿ô¤Ï
173 .BR flockfile ()
174 ¤Î¥Ö¥í¥Ã¥­¥ó¥°¤ò¹Ô¤ï¤Ê¤¤
175 ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¡£Â¾¤Î¥¹¥ì¥Ã¥É¤¬ \fI*filehandle\fP ¤ò¥í¥Ã¥¯¤·¤Æ¤¤¤ë»þ¤Ï
176 ²¿¤â¹Ô¤ï¤º¡¢¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï \fI*filehandle\fP ¤Î½êÍ­¸¢¤ò³ÍÆÀ¤·¡¢
177 ¥í¥Ã¥¯¿ô¤ò²Ã»»¤¹¤ë¡£
178 .\"O .SH "RETURN VALUE"
179 .SH ÊÖ¤êÃÍ
180 .\"O The
181 .\"O .BR ftrylockfile ()
182 .\"O function returns zero for success
183 .\"O (the lock was obtained), and nonzero for failure.
184 .BR ftrylockfile ()
185 ´Ø¿ô¤Ï¥í¥Ã¥¯¤ËÀ®¸ù¤¹¤ë¤È 0 ¤òÊÖ¤·¡¢
186 ¼ºÇÔ¤·¤¿¾ì¹ç¤Ï 0 °Ê³°¤ÎÃͤòÊÖ¤¹¡£
187 .\"O .SH ERRORS
188 .\"O None.
189 .SH ¥¨¥é¡¼
190 ¤Ê¤·¡£
191 .\"O .SH "CONFORMING TO"
192 .SH ½àµò
193 POSIX.1-2001.
194 .\"O .SH AVAILABILITY
195 .SH ²ÄÍÑÀ­
196 .\"O These functions are available when
197 .\"O .B _POSIX_THREAD_SAFE_FUNCTIONS
198 .\"O is defined.
199 .\"O They are in libc since libc 5.1.1 and in glibc
200 .\"O since glibc 2.0.
201 .B _POSIX_THREAD_SAFE_FUNCTIONS
202 ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤È¤­¤Ë¤³¤ì¤é¤Î´Ø¿ô¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
203 5.1.1 °Ê¹ß¤Î libc ¤È 2.0 °Ê¹ß¤Î glibc ¤Ë¸ºß¤¹¤ë¡£
204 .\"O .SH "SEE ALSO"
205 .SH ´ØÏ¢¹àÌÜ
206 .BR unlocked_stdio (3)