flockfile()— stdio locking

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 3

both  z/OS V1R8

Format

#define _UNIX03_SOURCE 
#include <stdio.h>

void flockfile(FILE *file);

General description

This function provides explicit application-level locking of stdio (FILE*) objects. The flockfile() family of the functions can be used by a thread to delineate a sequence of I/O statements that are executed as a unit.

The flockfile() function acquires ownership of a (FILE*) object for the thread, waiting if necessary, and increases the internal lock count. If the thread has previously been granted ownership, the internal lock count is increased.

The internal lock count allows matching calls to flockfile() (or successful calls to ftrylockfile()) and funlockfile() to be nested.

z/OS® Consideration: The flockfile() family of functions acts upon FILE * objects. It is possible to have the same physical file represented by multiple FILE * objects that are not recognized as being equivalent. For example, fopen() opens a file and open() opens the same file, and then fdopen() creates a FILE * object. In this case, locking the first FILE * does not prevent the second FILE * from also being locked and used.

Returned value

None.

Notes:
  1. Because the flockfile() function returns void, no error information can be returned.
  2. It is the application’s responsibility to prevent deadlock (or looping). For example, deadlock (or looping) may occur if a (FILE *) object is closed, or a thread is terminated, before relinquishing all locked (FILE *) objects.

Related information