flock/fcntl

X

xhoster

from perldoc -f flock:

Note also that some versions of "flock" cannot lock things
over the network; you would need to use the more
system-specific "fcntl" for that. If you like you can force
Perl to ignore your system's flock(2) function, and so
provide its own fcntl(2)-based emulation, by passing the
switch "-Ud_flock" to the Configure program when you
configure perl.

Is there an easy way (a pragma or switch or something) to obtain the fcntl
based emulation *without* needing to recompile perl? Also, since flock
seems to be Perl's first choice over fcntl, I wonder why that is. What
disadvantages does building Perl with -Ud_flock have, other than this one:

Note that the fcntl(2) emulation of flock(3) requires that
FILEHANDLE be open with read intent to use LOCK_SH and
requires that it be open with write intent to use LOCK_EX.

Thanks,

Xho
 
B

Ben Morrow

Quoth (e-mail address removed):
from perldoc -f flock:

Note also that some versions of "flock" cannot lock things
over the network; you would need to use the more
system-specific "fcntl" for that. If you like you can force
Perl to ignore your system's flock(2) function, and so
provide its own fcntl(2)-based emulation, by passing the
switch "-Ud_flock" to the Configure program when you
configure perl.

Is there an easy way (a pragma or switch or something) to obtain the fcntl
based emulation *without* needing to recompile perl?

Not that I know of, but it would be trivial to write a replacement
yourself which calls fcntl.
Also, since flock
seems to be Perl's first choice over fcntl, I wonder why that is. What
disadvantages does building Perl with -Ud_flock have, other than this one:

Note that the fcntl(2) emulation of flock(3) requires that
FILEHANDLE be open with read intent to use LOCK_SH and
requires that it be open with write intent to use LOCK_EX.

fcntl locks

- can lead to unavoidable deadlocks (which the kernel ought to
detect for you).

- are often slower.

- aren't inherited across forks.

It's important to realize that the semantics are different:

flock $FH, LOCK_SH;
flock $FH, LOCK_EX;

will unlock the shared lock before applying the exclusive with flock(2),
but not with fcntl(2) emulation. This is the cause of the potential
deadlock, and the need to do deadlock detection is why locks can't be
inherited.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top