FLOCKFILE(3) BSD Programmer's Manual FLOCKFILE(3)
flockfile, ftrylockfile, funlockfile - application level locking of stdio files
#include <stdio.h> void flockfile(FILE *file); int ftrylockfile(FILE *file); void funlockfile(FILE *file);
The flockfile(), ftrylockfile(), and funlockfile() functions provide for explicit application-level locking of stdio FILE * objects. These func- tions 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 is used by a thread to acquire ownership of a FILE * object. The ftrylockfile() function is used by a thread to acquire ownership of a FILE * object if the object is available; ftrylockfile() is a non- blocking version of flockfile(). The funlockfile() function is used to relinquish the ownership granted to the thread. The behaviour is undefined if a thread other than the current owner calls the funlockfile() function. Logically, there is a lock count associated with each FILE * object. This count is implicitly initialized to zero when the FILE * object is creat- ed. The FILE * object is unlocked when the count is zero. When the count is positive, a single thread owns the FILE * object. When the flockfile() function is called, if the count is zero or if the count is positive and the caller owns the FILE * object, the count is incremented. Otherwise, the calling thread is suspended, waiting for the count to return to zero. Each call to funlockfile() decrements the count. This allows matching calls to flockfile() (or successful calls to ftrylockfile()) and funlock- file() to be nested. Library functions that reference FILE * behave as if they use flockfile() and funlockfile() internally to obtain ownership of these FILE * objects.
None for flockfile() and funlockfile(). The function ftrylock() returns zero for success and non-zero to indicate that the lock cannot be ac- quired.
getc_unlocked(3), getchar_unlocked(3), pthreads(3), putc_unlocked(3), putchar_unlocked(3)
flockfile(), ftrylockfile() and funlockfile() conform to ISO/IEC 9945-1 ANSI/IEEE ("POSIX") Std 1003.1c/D10. MirOS BSD #10-current August 20, 1998 1
Generated on 2015-10-06 19:36:22 by $MirOS: src/scripts/roff2htm,v 1.80 2015/01/02 13:54:19 tg Exp $
These manual pages and other documentation are copyrighted by their respective writers;
their source is available at our CVSweb,
AnonCVS, and other mirrors. The rest is Copyright © 2002–2015 The MirOS Project, Germany.
This product includes material provided by Thorsten Glaser.
This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.