2 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH flockfile 3 (date) "Linux man-pages (unreleased)"
8 flockfile, ftrylockfile, funlockfile \- lock FILE for stdio
11 .RI ( libc ", " \-lc )
16 .BI "void flockfile(FILE *" filehandle );
17 .BI "int ftrylockfile(FILE *" filehandle );
18 .BI "void funlockfile(FILE *" filehandle );
22 Feature Test Macro Requirements for glibc (see
23 .BR feature_test_macros (7)):
26 All functions shown above:
28 /* Since glibc 2.24: */ _POSIX_C_SOURCE >= 199309L
29 || /* glibc <= 2.23: */ _POSIX_C_SOURCE
30 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
33 The stdio functions are thread-safe.
34 This is achieved by assigning
37 object a lockcount and (if the lockcount is nonzero)
39 For each library call, these functions wait until the
42 is no longer locked by a different thread, then lock it, do the
43 requested I/O, and unlock the object again.
45 (Note: this locking has nothing to do with the file locking done
51 All this is invisible to the C-programmer, but there may be two
52 reasons to wish for more detailed control.
53 On the one hand, maybe
54 a series of I/O actions by one thread belongs together, and should
55 not be interrupted by the I/O of some other thread.
56 On the other hand, maybe the locking overhead should be avoided
57 for greater efficiency.
59 To this end, a thread can explicitly lock the
62 then do its series of I/O actions, then unlock.
64 other threads from coming in between.
65 If the reason for doing
66 this was to achieve greater efficiency, one does the I/O with
67 the nonlocking versions of the stdio functions: with
81 no longer locked by a different thread, then makes the
82 current thread owner of
89 function decrements the lock count.
93 function is a nonblocking version
96 It does nothing in case some other thread
99 and it obtains ownership and increments
100 the lockcount otherwise.
104 function returns zero for success
105 (the lock was obtained), and nonzero for failure.
109 For an explanation of the terms used in this section, see
117 Interface Attribute Value
122 T} Thread safety MT-Safe
128 POSIX.1-2001, POSIX.1-2008.
130 These functions are available when
131 .B _POSIX_THREAD_SAFE_FUNCTIONS
134 .BR unlocked_stdio (3)