Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ftrylockfile(3) [osf1 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)

Check Out this Related Man Page

flockfile(3C)						   Standard C Library Functions 					     flockfile(3C)

NAME
flockfile, funlockfile, ftrylockfile - acquire and release stream lock SYNOPSIS
#include <stdio.h> void flockfile(FILE *stream); void funlockfile(FILE *stream); int ftrylockfile(FILE *stream); DESCRIPTION
The flockfile() function acquires an internal lock of a stream stream. If the lock is already acquired by another thread, the thread call- ing flockfile() is suspended until it can acquire the lock. In the case that the stream lock is available, flockfile() not only acquires the lock, but keeps track of the number of times it is being called by the current thread. This implies that the stream lock can be acquired more than once by the same thread. The funlockfile() function releases the lock being held by the current thread. In the case of recursive locking, this function must be called the same number of times flockfile() was called. After the number of funlockfile() calls is equal to the number of flockfile() calls, the stream lock is available for other threads to acquire. The ftrylockfile() function acquires an internal lock of a stream stream, only if that object is available. In essence ftrylockfile() is a non-blocking version of flockfile(). RETURN VALUES
The ftrylockfile() function returns 0 on success and non-zero to indicate a lock cannot be acquired. EXAMPLES
Example 1 A sample program of flockfile(). The following example prints everything out together, blocking other threads that might want to write to the same file between calls to fprintf(3C): FILE iop; flockfile(iop); fprintf(iop, "hello "); fprintf(iop, "world); fputc(iop, 'a'); funlockfile(iop); An unlocked interface is available in case performance is an issue. For example: flockfile(iop); while (!feof(iop)) { *c++ = getc_unlocked(iop); } funlockfile(iop); ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
Intro(3), __fsetlocking(3C), ferror(3C), fprintf(3C), getc(3C), putc(3C), stdio(3C), ungetc(3C), attributes(5), standards(5) NOTES
The interfaces on this page are as specified in IEEE Std 1003.1:2001. See standards(5). SunOS 5.11 10 Sep 2003 flockfile(3C)
Man Page