flockfile gives the calling thread ownership of file if file is not currently owned by another thread. A thread keeps ownership of the file until it calls funlockfile.
A thread that tries to get ownership of a file that is currently owned by another thread is suspended until the current owner relinquishes the file.
A thread can do multiple calls to flockfile and ftrylockfile and not get suspended if it currently owns the file, but an equal number of funlockfile calls are necessary to relinquish the object completely.