Interoperation of flock(2), fcntl(2), and lockf(3)
From: Yar Tikhiy (yar_at_comp.chem.msu.su)
Date: 05/15/04
- Previous message: Mark Terribile: "Re: kqueue giant-locking (&kq_Giant, locking)"
- Next in thread: Cyrille Lefevre: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Reply: Cyrille Lefevre: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Reply: Kirk McKusick: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 15 May 2004 13:21:14 +0400 To: arch@freebsd.org, hackers@freebsd.org
Hi folks,
I've always been confused by the following sentence from the lockf(3)
manpage:
The lockf(), fcntl(2) and flock(2) locks may be safely used
concurrently.
Does that mean that each of those calls uses a locking mechanism
of its own? Of course, in practice those calls use a mutual
mechanism, thus allowing serial access to a file from applications
using different calls. However, there's an oddity: While it's
possible for a process to obtain the same lock several times w/o
error (it's a no-op case of upgrading the lock,) intermixing flock(2)
and fcntl(2), or flock(2) and lockf(3), within the same process
results in EAGAIN upon the second locking attempt. That's while
mixing fcntl(2) and lockf(3) is all right as long as the latter
call is just a wrapper for the former one. Of course, intermixing
different lock calls within one process is a poor idea at the first
place, but I can imagine some mail application that tries to coax
all the mailbox locking schemes at once.
Considering all the above, I'd like to add the following paragraph
to the flock(2), lockf(3), and fcntl(2) man pages (replacing the
sentence quoted from lockf(3)):
The flock(2), fcntl(2), and lockf(3) locks are compatible.
Processes using different locking interfaces can cooperate
over the same file safely. However, only one of such
interfaces should be used within a process. If a file is
locked by a process through flock(2), any record within the
file will be seen as locked from the viewpoint of another
process using fcntl(2) or lockf(3), and vice versa.
Any objections or comments?
-- Yar _______________________________________________ freebsd-arch@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-arch To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
- Previous message: Mark Terribile: "Re: kqueue giant-locking (&kq_Giant, locking)"
- Next in thread: Cyrille Lefevre: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Reply: Cyrille Lefevre: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Reply: Kirk McKusick: "Re: Interoperation of flock(2), fcntl(2), and lockf(3)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
- Re: Interoperation of flock(2), fcntl(2), and lockf(3)
... Does that mean that each of those calls uses a locking mechanism ... error (it's
a no-op case of upgrading the lock,) intermixing flock ... To unsubscribe,
... (freebsd-arch) - Re: Locking a record in Access from vb.net
... pessimistic locking in ADO.NET. ... You could 'roll your own' locking mechanism.
... Add a flag field to your table. ... (microsoft.public.access.queries) - Interoperation of flock(2), fcntl(2), and lockf(3)
... Does that mean that each of those calls uses a locking mechanism ... error (it's
a no-op case of upgrading the lock,) intermixing flock ... (freebsd-hackers) - Re: Synchronized Collection
Recommendation
... All this locking will however slow things down for such things as ... Which
will now lock every time it reads something, ... Thread A increments i to the last
element ... used it just seems like one cannot reliably choose the locking mechanism ...
(microsoft.public.dotnet.languages.csharp) - Re[2]: SECURITY.NNOV: file locking and security (group policy DoS on Windows 2000 domain)
... I never intended to review all possible locking mechanism. ... to be open for
writing, so, it's behind advisory (I'm talking about READ ... I don't use linux.
... (Bugtraq)