| FLOCKFILE(3) | Library Functions Manual | FLOCKFILE(3) |
flockfile,
ftrylockfile, funlockfile
— locking for stdio streams
#include
<stdio.h>
void
flockfile(FILE
*file);
int
ftrylockfile(FILE
*file);
void
funlockfile(FILE
*file);
These functions provide application control over the locking of
stdio streams.
flockfile()
and
ftrylockfile()
increment the lock count associated with file on
behalf of the calling thread. If another thread owns the lock,
flockfile() blocks until the lock becomes available,
whereas ftrylockfile() returns immediately and
indicates failure.
When called by a thread holding the lock,
funlockfile()
decrements the lock count by one. When the lock count reaches zero, the
calling thread relinquishes ownership of the lock.
Functions such as fread(3) and fprintf(3) are internally thread safe by default, but additional locking may be used to coordinate sequences of multiple calls.
ftrylockfile() returns zero for success
and non-zero for failure.
These functions conform to.
These functions have been available since OpenBSD 2.5.
Reading from one stream can flush a different buffered output stream, leading to deadlocks.
| July 25, 2025 | Debian |