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

[MacPerl] CGI Threading & File Locking



On Sun, 20 Feb 2000 19:20:24 -0800 (PST), Michael Geffon wrote:

>I've been struggling to determine how people handle locking without an
>implementation of flock() on the Mac, but then it hit me that if the
>requests are processed sequentially and not concurrently this becomes a non-issue.
>
>Even if I don't have to worry about it in this case, how _do_ I lock a
>file under the MacOS should the need arise? There was some discussion on
>the list archives about it, but I didn't see a clear answer. Is there an
>accepted best practice for exclusive file locking on the Mac?

Well, open a file with write permission. If the file is already open,
this will fail. So:

 - There is a OS imposed (implicit) file locking mechanism, as soon as
you want to write to a file

 - In this case, open() will fail. This is completely different from the
situation under Unix.

You don't need an explicit flock(), but you need to check if the file
open failed, and if so, why. If it is because the file was "busy" (in my
tests, $! said "invalid argument"), try again later, after some delay.
(sleep()?)

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org