#include <stdio.h>
void flockfile(FILE *stream);
void funlockfile(FILE *stream);
int ftrylockfile(FILE *stream);
MT-Safe
funlockfile() 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.
ftrylockfile() acquires an internal lock of a stream stream, only if that object is available. In essence ftrylockfile() is a non-blocking version of flockfile().
FILE iop; flockfile(iop); fprintf(iop, "hello "); fprintf(iop, "world0); 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);See Also
intro(3) , ferror(3S) , getc(3S) , putc(3S) , stdio(3S) , ungetc(3S)Notes
The interfaces on this page are as specified in the POSIX 1003.1c standard.