2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
46 .TH FLOCKFILE 3C "Sep 10, 2003"
48 flockfile, funlockfile, ftrylockfile \- acquire and release stream lock
54 \fBvoid\fR \fBflockfile\fR(\fBFILE *\fR\fIstream\fR);
59 \fBvoid\fR \fBfunlockfile\fR(\fBFILE *\fR\fIstream\fR);
64 \fBint\fR \fBftrylockfile\fR(\fBFILE *\fR\fIstream\fR);
70 The \fBflockfile()\fR function acquires an internal lock of a stream
71 \fIstream\fR. If the lock is already acquired by another thread, the thread
72 calling \fBflockfile()\fR is suspended until it can acquire the lock. In the
73 case that the stream lock is available, \fBflockfile()\fR not only acquires the
74 lock, but keeps track of the number of times it is being called by the current
75 thread. This implies that the stream lock can be acquired more than once by
79 The \fBfunlockfile()\fR function releases the lock being held by the current
80 thread. In the case of recursive locking, this function must be called the
81 same number of times \fBflockfile()\fR was called. After the number of
82 \fBfunlockfile()\fR calls is equal to the number of \fBflockfile()\fR calls,
83 the stream lock is available for other threads to acquire.
86 The \fBftrylockfile()\fR function acquires an internal lock of a stream
87 \fIstream\fR, only if that object is available. In essence
88 \fBftrylockfile()\fR is a non-blocking version of \fBflockfile()\fR.
92 The \fBftrylockfile()\fR function returns \fB0\fR on success and non-zero to
93 indicate a lock cannot be acquired.
96 \fBExample 1 \fRA sample program of \fBflockfile()\fR.
99 The following example prints everything out together, blocking other threads
100 that might want to write to the same file between calls to \fBfprintf\fR(3C):
107 fprintf(iop, "hello ");
108 fprintf(iop, "world);
116 An unlocked interface is available in case performance is an issue. For
124 *c++ = getc_unlocked(iop);
133 See \fBattributes\fR(5) for descriptions of the following attributes:
141 ATTRIBUTE TYPE ATTRIBUTE VALUE
143 Interface Stability Standard
151 \fBIntro\fR(3), \fB__fsetlocking\fR(3C), \fBferror\fR(3C), \fBfprintf\fR(3C),
152 \fBgetc\fR(3C), \fBputc\fR(3C), \fBstdio\fR(3C), \fBungetc\fR(3C),
153 \fBattributes\fR(5), \fBstandards\fR(5)
157 The interfaces on this page are as specified in IEEE Std 1003.1:2001. See