Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Nov 1997 23:46:57 +1000
From:      Stephen McKay <syssgm@dtir.qld.gov.au>
To:        freebsd-hackers@freebsd.org
Cc:        syssgm@dtir.qld.gov.au
Subject:   Re: flock() question 
Message-ID:  <199711281346.XAA01518@ogre.dtir.qld.gov.au>
In-Reply-To: <Pine.BSF.3.95.971127234335.27255C-100000@alive.znep.com> from Marc Slemko at "Fri, 28 Nov 1997 06:51:22 %2B0000"
References:  <Pine.BSF.3.95.971127234335.27255C-100000@alive.znep.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday, 28th November 1997, Marc Slemko wrote:

>On Thu, 27 Nov 1997, Charles Mott wrote:
>
>Locking works fine.  It just doesn't do what you think it does.
>
>> guessed that locking would have worked in both situations.  I am running
>> 2.2.2-R.
>
>from the man page:
>
>     Locks are on files, not file descriptors.  That is, file descriptors du-
>     plicated through dup(2) or fork(2) do not result in multiple instances of
>     a lock, but rather multiple references to a single lock.  If a process
>     holding a lock on a file forks and the child explicitly unlocks the file,
>     the parent will lose its lock.

It's not entirely obvious from this that 1) your own exclusive lock will
not prevent you from trying to assert an exclusive lock and 2) you are
identified by your file table entry.  In other words, you can lock the
same file over and over and it doesn't nest.  And you and your child are
the same locker because you refer to the same file table entry.  This
is the mechanism in action in the first example program.

It's so obscure that I think a manpage rewrite is in order, probably with
some sample usage.  For example, locks don't really apply to "files"
(ie dev/inode) but to "file table entries" (ie channels to files), so
an example that opens the same file twice and attempts to lock both
file descriptors would deadlock.  A few of these should scare most
people off. :-)

Please beat me to this rewrite.  Otherwise it goes on my list.  Bit
dusty that list, but if the "rellies" leave me alone this Christmas
we might see some action. :-)

Stephen.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199711281346.XAA01518>