funlockfile() — stdio unlocking

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 3

both  z/OS V1R8

Format

#define _UNIX03_SOURCE 
#include <stdio.h>

void funlockfile(FILE *file);

General description

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

The funlockfile() function reduces the internal lock count. When the count is reduced to zero, the funlockfile() function relinquishes the ownership granted to the thread, of a (FILE *) object. If a call to funlockfile() is made by a thread which has not been granted ownership of a (FILE *) object, the call is ignored and the lock count is not reduced

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 funlockfile() function returns void, no error information can be returned. If an invalid (FILE *) object is input, it will be ignored.
  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