1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
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>
28 .\"WORD: lockcount ロック数
29 .\"WORD: owner thread 所有者スレッド
31 .TH FLOCKFILE 3 2008-08-29 "" "Linux Programmer's Manual"
33 .\"O flockfile, ftrylockfile, funlockfile \- lock FILE for stdio
35 flockfile, ftrylockfile, funlockfile \- 標準入出力 FILE のロックを行う
41 .BI "void flockfile(FILE *" filehandle );
43 .BI "int ftrylockfile(FILE *" filehandle );
45 .BI "void funlockfile(FILE *" filehandle );
49 .\"O Feature Test Macro Requirements for glibc (see
50 .\"O .BR feature_test_macros (7)):
52 .RB ( feature_test_macros (7)
57 .\"O All functions shown above:
60 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
61 _SVID_SOURCE || _POSIX_SOURCE
66 .\"O The stdio functions are thread-safe.
67 .\"O This is achieved by assigning
70 .\"O object a lockcount and (if the lockcount is nonzero)
71 .\"O an owning thread.
72 標準入出力関数はスレッドセーフである。これは、各
74 オブジェクトに対し、ロック数 (lockcount) と
75 (ロック数が 0 でない場合は) 所有者スレッド (owner thread)
77 .\"O For each library call, these functions wait until the
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 ライブラリの呼び出しが行われる毎に、標準入出力関数は
84 オブジェクトが他のスレッドによってロックされていない状態になるまで待ち、
86 オブジェクトをロックし、要求されて入出力を行い、
89 .\"O (Note: this locking has nothing to do with the file locking done
90 .\"O by functions like
98 といった関数が行うロックとは全く無関係である。)
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 ロックのオーバヘッドを避ける必要があるということであろう。
113 .\"O To this end, a thread can explicitly lock the
116 .\"O then do its series of I/O actions, then unlock.
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)
124 .\"O .BR putc_unlocked (3)
131 オブジェクトのロック、一連の入出力動作の実行、
132 ロックの解除をスレッドが明示的に指示することができる。
133 これにより、他のスレッドが途中で入出力を行うのを防止する。
134 このようなことを行う理由が効率の向上であるならば、
135 ロックを行わないバージョンの標準入出力関数を使うこともできる。
141 .BR getc_unlocked (3)
143 .BR putc_unlocked (3)
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
153 関数は、\fI*filehandle\fP が他のスレッドにロックされていな
154 い状態になるまで待ったのち、現在のスレッドを \fI*filehandle\fP のオーナに設
158 .\"O .BR funlockfile ()
159 .\"O function decrements the lock count.
164 .\"O .BR ftrylockfile ()
165 .\"O function is a nonblocking version
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.
175 バージョンである。他のスレッドが \fI*filehandle\fP をロックしている時は
176 何も行わず、そうでない場合は \fI*filehandle\fP の所有権を獲得し、
178 .\"O .SH "RETURN VALUE"
181 .\"O .BR ftrylockfile ()
182 .\"O function returns zero for success
183 .\"O (the lock was obtained), and nonzero for failure.
191 .\"O .SH "CONFORMING TO"
194 .\"O .SH AVAILABILITY
196 .\"O These functions are available when
197 .\"O .B _POSIX_THREAD_SAFE_FUNCTIONS
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 に存在する。
206 .BR unlocked_stdio (3)