Should two exclusive flock(2)'s by same process succeed?

alan l wendt wendt at segovia.CS.ColoState.Edu
Fri Jul 28 07:00:20 AEST 1989


The second exclusive lock should fail, because that's safer.
The two calls might very well be embedded deep in libraries and
not know about each other.  If you do an flock it's usually because
you intend to read something in and modify it, and if you allow
pairs of locks in the same process you can get duplicated bits of
data.  With two widely separated flock calls for which you may
not even have source code, you can't assume that the conflict
is benign.

If you want conflicting locks to succeed within a single process,
on the other hand, it will usually be because you yourself are
writing both flock calls and know that the conflict is benign.
In that case, you can easily implement your preference by interpolating
your own manager in between your calls and the calls on flock.

Alan Wendt



More information about the Comp.unix.questions mailing list