flockfile()

Acquire ownership of a file

Synopsis:

#include <stdio.h>

void flockfile( FILE* file );

Since:

BlackBerry 10.0.0

Arguments:

file
A pointer to the FILE object for the file you want to lock.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

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 flockfile() function is used by a thread to acquire ownership of a FILE. The ftrylockfile() function is a nonblocking version of flockfile(). To unlock the file, call funlockfile().

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.

Classification:

POSIX 1003.1 TSF

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus