The flockfile() function acquires an internal lock of a stream stream. If the lock is already acquired by another thread, the thread calling flockfile() is suspended until it can acquire the lock. In the case that the stream lock is available, flockfile() not only acquires the lock, but keeps track of the number of times
it is being called by the current thread. This implies that the stream lock can be acquired more than once by the same thread.
The funlockfile() function releases the lock being held by the current thread. In the case of recursive locking, this function must be called the same number of times flockfile() was called. After the number of funlockfile() calls is equal to the number of flockfile() calls, the stream lock is available for other threads
to acquire.
The ftrylockfile() function acquires an internal lock of a stream stream, only if that object is available. In essence ftrylockfile()
is a non-blocking version of flockfile().
|