Acquire ownership of a file
#include <stdio.h> void flockfile( FILE* file );
- A pointer to the FILE object for the file you want to lock.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The flockfile() function provides for explicit application-level locking of stdio (FILE) objects. This function can be used by a thread to delineate a sequence of I/O statements that are to be executed as a unit.
The implementation acts as if there is a lock count associated with each FILE. This count is implicitly initialized to zero when the FILE is created. The FILE object is unlocked when the count is zero. When the count is positive, a single thread owns the FILE. When the flockfile() function is called, if the count is zero or if the count is positive and the caller owns the FILE, the count is incremented. Otherwise, the calling thread is suspended, waiting for the count to return to zero.
Last modified: 2014-06-24