Visit Our UNIX and Linux User Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #748
Difficulty: Medium
The ZX81 was a home computer that was produced by Sinclair Research and manufactured in Dundee, Scotland.
True or False?
Linux & Unix Commands - Search Man Pages

flockfile(3s) [hpux man page]

flockfile(3S)															     flockfile(3S)

NAME
flockfile(), ftrylockfile(), funlockfile() - explicit locking of streams within a multithread application SYNOPSIS
DESCRIPTION
The and functions provide for explicit application-level locking of streams. 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 function is used by a thread to acquire ownership of a object. The function is used by a thread to acquire ownership of a object if the object is available; is a non-blocking version of The function is used to relinquish the ownership granted to the thread. The behavior is undefined if a thread other than the current owner calls the function. Logically, there is a count associated with each stream. This count is implicitly initialized to zero when the stream is created. The stream is unlocked when the count is zero. When the count is positive, a single thread owns the stream. When the function is called, if the count is zero or if the count is positive and the caller owns the stream, the count is incremented. Otherwise, the calling thread is suspended, waiting for the count to return to zero. Each call to decrements the count. This allows matching calls to (or successful calls to and to be nested. All POSIX.1 and C standard functions that reference objects behave as if they use and internally to obtain ownership of these objects. RETURN VALUE
None for and The function returns zero for success and nonzero to indicate that the lock cannot be acquired. flockfile(3S)

Check Out this Related 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

Featured Tech Videos