[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] file locking



I was thinking more about flock() under MacPerl.

If I open a file for writing in MacPerl and then sleep(), and then try to
write to that file from another application (or another MacPerl script
under another MacPerl app), I get a Mac OS error.  MacPerl sets the flag
that says "I'm writing to the file, wait until I am done."

Seems to me that flock() is already partially "supported" by MacPerl.  That
is, you can set a lock.  When you open a file, you have to set a lock.  You
can't set a blocking lock.  You can, of course, emulate a blocking lock
with while:

  until ($x) {
    open(A, ">a") && $x++;
  }

Not perfect, because not being able to achieve "lock" might mean the path
does not exist (i.e., the open might fail for another reason).

But the point is that MacPerl already has the concept of locking built-in
when you open files.  Just add blocking.  Of course, there would be no
distinction between LOCK_EX and LOCK_SH.  I'm not sure which would be
better to have, pretend they are all LOCK_EX or pretend they are all
LOCK_SH.  The former would be less dangerous, I think.  That way you know
that no one would change a file while someone is reading from it.

Just kinda rambling here late at night.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch