wrote:
> Hello newsgroup,
>
> Fortran is my syntax of choice for my avocation in numerical analysis,
> but perl is the much better tool for the net. For one of the better
> fortran sites, they have this counter:
>
> http://www.fortranlib.com/flcounter.perl
>
> If the open statement in this:
>
> sub check_lock {
> $time = $_[0];
>
> for ($i = 1;$i <= $time; $i++) {
> if (-e "$data_dir$lock_file") {
> sleep 1;
> }
> else {
> open(LOCK,">$data_dir$lock_file");
> print LOCK "0";
> close(LOCK);
> last;
> }
> }
> }
>
> is changed to this:
>
> sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT) or die $!;
>
> do they have a better program?
That depends. I tend to think that all sub-values of "broken" are
equal, but sometimes some things can be more broken than others.
The current code has a race condition. The change detects the race
condition, but upon detecting it it aborts rather than recovering.
Maybe:
sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT) or
($!{EEXIST} and redo) or die $!;
However, that still seems to have the problem that if the lock attempt
times out, it proceeds as if the lock was obtained even though it hasn't
been.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.