flockfile

Acquires an application-level lock of a file object.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  void flockfile (
     FILE   *fp);
  

Parameters

fp

(IN) Points to the file object to lock.

Remarks

The flockfile function behaves as if there is a lock count associated with each file object or stream. This count is initialized to zero when the file object is created. 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, the count is incremented on the following conditions:

  • The count is zero

  • The count is positive and the caller owns the file object. This allows matching calls to flockfile and funlockfile to be nested.

Otherwise, the calling thread is suspended, waiting for the count to return to zero. Each call to the funlockfile function decrements the count.

All functions that reference file objects behave as if they use flockfile and funlockfile internally to obtain ownership of these file objects.

See Also