FLOCKFILE(3) BSD Programmer's Manual FLOCKFILE(3)NAME
flockfile, ftrylockfile, funlockfile - synchronize stdio calls from mul-
tiple threads.
SYNOPSIS
#include <pthread.h>
#include <stdio.h>
void
flockfile(FILE *stream);
int
ftrylockfile(FILE *stream);
void
funlockfile(FILE *stream);
DESCRIPTION
This interface is defined by IEEE Std1003.1c (``POSIX''). The
flockfile(), ftrylockfile(), and funlockfile() functions provide a mecha-
nism to synchronize access to a stdio stream across multiple threads.
These functions may be used by a thread to delineate a sequence of stdio
calls that should be executed as a unit.
The flockfile() function is used by a thread to guarantee exclusive own-
ership of a stdio stream. The calling thread will block until the lock
can be completed.
The ftrylockfile() function is a non-blocking version of flockfile().
The flockfile() and ftrylockfile() calls are associated with a lock count
and a thread holding the lock may call flockfile multiple times without
concern for deadlock. The stdio stream is unlocked when a corresponding
number of calls to funlockfile() are completed.
The funlockfile() function releases a previously held lock or if
flockfile() has been called multiple times decreases the lock count for
the current thread. When the lock count decreases to zero the stream is
unlocked. When funlockfile() causes a lock on a stdio stream to be re-
leased at most one thread waiting for the lock will proceed.
RETURN VALUES
The flockfile() and funlockfile() functions return no value.
The ftrylockfile() function returns 0 if a lock was successfully ac-
quired, and non-zero otherwise.
SEE ALSOpthreads(3), getc_unlocked(3), getchar_unlocked(3), putc_unlocked(3),
putchar_unlocked(3)STANDARDS
The flockfile, ftrylockfile, and funlockfile functions conform to IEEE
Std1003.1c (``POSIX'').
HISTORY
The flockfile, ftrylockfile, and funlockfile functions first appeared in
BSD/OS 3.0.
BSDI BSD/OS June 3, 1996 1