1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH FLOCKFILE 3 2008-08-29 "" "Linux Programmer's Manual"
27 flockfile, ftrylockfile, funlockfile \- lock FILE for stdio
32 .BI "void flockfile(FILE *" filehandle );
34 .BI "int ftrylockfile(FILE *" filehandle );
36 .BI "void funlockfile(FILE *" filehandle );
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
45 All functions shown above:
47 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
48 _SVID_SOURCE || _POSIX_SOURCE
52 The stdio functions are thread-safe.
53 This is achieved by assigning
56 object a lockcount and (if the lockcount is nonzero)
58 For each library call, these functions wait until the
61 is no longer locked by a different thread, then lock it, do the
62 requested I/O, and unlock the object again.
64 (Note: this locking has nothing to do with the file locking done
70 All this is invisible to the C-programmer, but there may be two
71 reasons to wish for more detailed control.
72 On the one hand, maybe
73 a series of I/O actions by one thread belongs together, and should
74 not be interrupted by the I/O of some other thread.
75 On the other hand, maybe the locking overhead should be avoided
76 for greater efficiency.
78 To this end, a thread can explicitly lock the
81 then do its series of I/O actions, then unlock.
83 other threads from coming in between.
84 If the reason for doing
85 this was to achieve greater efficiency, one does the I/O with
86 the nonlocking versions of the stdio functions: with
100 no longer locked by a different thread, then makes the
101 current thread owner of
108 function decrements the lock count.
112 function is a nonblocking version
115 It does nothing in case some other thread
118 and it obtains ownership and increments
119 the lockcount otherwise.
123 function returns zero for success
124 (the lock was obtained), and nonzero for failure.
130 These functions are available when
131 .B _POSIX_THREAD_SAFE_FUNCTIONS
133 They are in libc since libc 5.1.1 and in glibc
136 .BR unlocked_stdio (3)