[boulder.pm] open vs. sysopen

jeff jeff at planetoid.net
Thu Jan 18 14:50:12 CST 2001


is the lisa tutorial available to the public.

> It turns out that locking a file for writing without leaving a
> race-condition problem is more difficult than expected, and from year
> to year I've noticed the "right" advice changing.  The latest I've seen
> is what I had in the nicevi code:
>
> sysopen(LAUNCH_CODES, "$f", O_WRONLY | O_CREAT) or die "Urk!  $!";
> flock(LAUNCH_CODES, LOCK_EX|LOCK_NB) or die "Aah! $!";
>
> # doodle doodle doodle
>
> flock(LAUNCH_CODES, LOCK_UN) or die "Yarrgh! $!";
> close(LAUNCH_CODES);
>
> In the above code, you don't need the |LOCK_NB
> but the flock call will block (the program will hang) until
> the exclusive lock is obtained if you do that.  Personally,
> I don't.
>
> I don't pretend to understand the minutiae of why exactly that
> sequence of function calls and flags does the job, but I do trust
> that Tom Christiansen (I got the above code in a LISA tutorial) has
> a better understanding of it than I do.  So, yes, it's a bit of
> cargo-cult programming.
>

--
T_r_i_k_M_e_d_i_a
http://www.trikmedia.com






More information about the Boulder-pm mailing list