Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

funlockfile(3) [netbsd man page]

FLOCKFILE(3)						   BSD Library Functions Manual 					      FLOCKFILE(3)

NAME
flockfile, ftrylockfile, funlockfile -- stdio stream locking functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> void flockfile(FILE *file); int ftrylockfile(FILE *file); void funlockfile(FILE *file); DESCRIPTION
The flockfile(), ftrylockfile(), and funlockfile() functions provide applications with explicit control of locking of stdio stream objects. They can be used by a thread to execute a sequence of I/O operations as a unit, without interference from another thread. Locks on stdio streams are recursive, and a lock count is maintained. stdio streams are created unlocked, with a lock count of zero. After successful acquisition of the lock, its count is incremented to one, indicating locked state of the stdio stream. Each subsequent relock operation performed by the owner thread increments the lock count by one, and each subsequent unlock operation performed by the owner thread decrements the lock count by one, allowing matching lock and unlock operations to be nested. After its lock count is decremented to zero, the stdio stream returns to unlocked state, and ownership of the stdio stream is relinquished. The flockfile() function acquires the ownership of file for the calling thread. If file is already owned by another thread, the calling thread is suspended until the acquisition is possible (i.e., file is relinquished again and the calling thread is scheduled to acquire it). The ftrylockfile() function acquires the ownership of file for the calling thread only if file is available. The funlockfile() function relinquishes the ownership of file previously granted to the calling thread. Only the current owner of file may funlockfile() it. RETURN VALUES
If successful, the ftrylockfile() function returns 0. Otherwise, it returns non-zero to indicate that the lock cannot be acquired. SEE ALSO
flock(2), getc_unlocked(3), getchar_unlocked(3), lockf(3), putc_unlocked(3), putchar_unlocked(3) STANDARDS
The flockfile(), ftrylockfile() and funlockfile() functions conform to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
The flockfile() function first appeared in FreeBSD 2.0. BUGS
The design of these interfaces does not allow for addressing the problem of priority inversion. BSD
October 15, 2011 BSD

Check Out this Related Man Page

flockfile(3)						     Library Functions Manual						      flockfile(3)

NAME
flockfile, ftrylockfile, funlockfile - stdio locking functions LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <stdio.h> void flockfile( FILE * file); int ftrylockfile( FILE * file); void funlockfile( FILE * file); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: flockfile, funlockfile: POSIX.1c, XSH5.0 ftrylockfile: XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the stream to be locked. DESCRIPTION
The flockfile(), ftrylockfile, and funlockfile functions provide for explicit application-level locking of stdio (FILE*) objects. These functions can be used by a thread to delineate a sequence of I/O statements that are to be executed as a unit. The flockfile() function locks a stdio stream so that a thread can have exclusive use of that stream for multiple I/O operations. Use the flockfile() function for a thread that wishes to ensure that the output of several printf() functions, for example, is not garbled by another thread also trying to use printf(). The ftrylockfile() function is used by a thread to acquire ownership of a stdio (FILE*) object if the object is available. The ftrylock- file() function is a non-blocking version of flockfile(). The funlockfile() function unlocks a stdio stream, causing the thread that had been holding the lock to relinquish exclusive use of the stream. The behavior of the flockfile() and funlockfile() functions is unspecified if the file parameter does not point to a valid FILE structure. The behavior of funlockfile() is also unspecified if a thread other than the current owner calls funlockfile(). Matching flockfile() and funlockfile() calls can be nested. If the stream has been locked recursively, it will remain locked until the last matching funlockfile() is called. RETURN VALUE
None for flockfile() and funlockfile(). The ftrylockfile() function returns zero for success and non-zero to indicate that the lock cannot be acquired. RELATED INFORMATION
Functions: getc_unlocked(3), putc_unlocked(3) delim off flockfile(3)
Man Page