flock/fcntl

Discussion in 'Perl Misc' started by xhoster@gmail.com, Jul 13, 2006.

  1. Guest

    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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Jul 13, 2006
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    > 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

    --
    Musica Dei donum optimi, trahit homines, trahit deos. |
    Musica truces mollit animos, tristesque mentes erigit.|
    Musica vel ipsas arbores et horridas movet feras. |
     
    Ben Morrow, Jul 13, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Omid Fatemi

    fcntl and FCNTL

    Omid Fatemi, Oct 30, 2004, in forum: Python
    Replies:
    4
    Views:
    6,909
    Steve Holden
    Nov 1, 2004
  2. thakadu
    Replies:
    3
    Views:
    523
    thakadu
    Nov 4, 2005
  3. Mitko Haralanov

    Invalid argument with fcntl.fcntl

    Mitko Haralanov, Jun 6, 2007, in forum: Python
    Replies:
    0
    Views:
    557
    Mitko Haralanov
    Jun 6, 2007
  4. Replies:
    1
    Views:
    1,835
    Jens Henrik Leonhard Jensen
    Jun 22, 2008
  5. Ara.T.Howard

    flock vs fcntl and nfs

    Ara.T.Howard, Nov 5, 2003, in forum: Ruby
    Replies:
    0
    Views:
    168
    Ara.T.Howard
    Nov 5, 2003
Loading...

Share This Page