fcntl(F_OFD_SETLK)
locks on an open file table entry, (usually obtained by open()
). Easy to understand.
But in the following example :
In its example process, each thread calls open()
, so each file descriptor should point to a different open file table entry.
Then doing fcntl (fd, F_OFD_SETLKW, &lck)
in each thread is just getting a lock on a different open file table entry, which means this locking is completely wrong.
But I tested on Ubuntu, and it works for some reason. What am I missing?
Old question but: multiple file descriptors can point to the same open file description. In this case, the
OFD
-style calls set advisory locks on the description itself (and thus is non-portable as it is a Linux concept) rather than the descriptor. Subtle difference.