In article <46***********************@per-qv1-newsreader-01.iinet.net.au>,
Gianni Mariani <gi*******@mariani.wswrote:
>Matt Brandt wrote:
>I am trying to get multiple threads to lock specific regions of a file.
However, since each thread has the same PID, it appears that a lock by
one thread does not block another thread from the same process.
>How does one maintain file locking between sibling threads?
>You should not be using file locking to protect between the same
threads. On the other hand, if the file handles are different, it may
be that file locking will work even within the same thread on different
file handles.
Unfortunately your answer to this off-topic question was not correct.
POSIX, for example, defines most attributes as being related to
the file descriptor (fd), not the file handle (FILE*) --
but when it comes to POSIX locking:
NOTES
Locks are on files, not file descriptors. That is, file descriptors
duplicated through dup(3C) (but not through fork(2), see the BUGS section
below) do not result in multiple instances of a lock, but rather multiple
references to a single lock.
This has some interesting and probably unintended consequences that can
result in early loss of the lock.
Correct locking is platform specific, and needs to be referred to
a platform specific newsgroup.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton