These functions provide explicit application-level locking of stdio streams.
They can be used to avoid output from multiple threads being interspersed,
input being dispersed among multiple readers, and to avoid the overhead
of locking the stream for each operation.
function acquires an exclusive lock on the specified stream.
If another thread has already locked the stream,
will block until the lock is released.
function is a non-blocking version of
if the lock cannot be acquired immediately,
returns non-zero instead of blocking.
function releases the lock on a stream acquired by an earlier call to
These functions behave as if there is a lock count associated
with each stream.
is called on the stream, the count is incremented,
and each time
is called on the stream, the count is decremented.
The lock is only actually released when the count reaches zero.