[forwarded submission from a non-member address -- rjk]


From: Uri Guttman <[EMAIL PROTECTED]>
Date: Wed, 31 Oct 2001 15:07:14 -0500
Subject: Re: [Boston.pm] warmfuzzies while locking file
To: [EMAIL PROTECTED]
CC: [EMAIL PROTECTED], [EMAIL PROTECTED]

>>>>> "JT" == John Tobey <[EMAIL PROTECTED]> writes:

  JT> If by "work" you mean do something useful, yes, this might "work".
  JT> However, it misses my point (that flock() returns a value that one
  JT> ought not ignore).  It may fail and return undef if the filesystem
  JT> does not support locks, because of some resource shortage, or because
  JT> the Yankees won.  It is really easy in Perl to check a return value
  JT> that you assume to be always true: add "or die".

  JT> I've used flock() in perhaps half a dozen Perl programs over my
  JT> career, and every time I reread perldoc -f flock.

check out the perl cookbook for a portable and better lock that uses
mkdir as an atomic lock. it has several advantages as it works over the
net and it works over multiple platforms. i wrote my own version of it
for a project a few years ago. one point, it creates a separate lock and
doesn't lock a particular file. this is good when you want to lock a
bunch of files at once. it does have one problem of cleaning up if your
program doesn't exit nicely whereas flock will release no matter what
when a program exits. this can be worked around too.

uri

-- 
Uri Guttman  ---------  [EMAIL PROTECTED]  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org

Reply via email to