1 .\" $NetBSD: flockfile.3,v 1.3 2003/04/16 13:34:44 wiz Exp $
3 .\" Copyright (c) 2003 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
37 .Nd stdio stream locking functions
43 .Fn flockfile "FILE *file"
45 .Fn ftrylockfile "FILE *file"
47 .Fn funlockfile "FILE *file"
54 functions provide applications with explicit control of locking of
56 They can be used by a thread to execute a sequence of I/O operations
57 as a unit, without interference from another thread.
59 Locks on stdio streams are recursive, and a lock count is maintained.
60 stdio streams are created unlocked, with a lock count of zero.
61 After successful acquisition of the lock, its count is incremented
62 to one, indicating locked state of the stdio stream.
63 Each subsequent relock operation performed by the owner thread
64 increments the lock count by one, and each subsequent unlock
65 operation performed by the owner thread decrements the lock count by one,
66 allowing matching lock and unlock operations to be nested.
67 After its lock count is decremented to zero, the stdio stream returns
68 to unlocked state, and ownership of the stdio stream is relinquished.
72 function acquires the ownership of
74 for the calling thread.
77 is already owned by another thread, the calling thread is suspended
78 until the acquisition is possible (i.e.,
80 is relinquished again and the calling thread is scheduled to acquire it).
84 function acquires the ownership of
86 for the calling thread only if
92 function relinquishes the ownership of
94 previously granted to the calling thread.
95 Only the current owner of
104 Otherwise, it returns non-zero to indicate that the lock cannot be acquired.
106 .Xr getc_unlocked 3 ,
107 .Xr getchar_unlocked 3 ,
108 .Xr putc_unlocked 3 ,
109 .Xr putchar_unlocked 3
119 The design of these interfaces does not allow for addressing the
120 problem of priority inversion.