open ERROR, '>', $file unless -e $file;
close ERROR;
And even in a full directory and an a loaded system, that time is going to be measured--assuming you can actually measure it at all--in low milliseconds at the most.
Now, what does that actually mean?
It means that one of the other processes encountered the same error as you, and succeeded in creating the error file within those few milliseconds. So what?
You then immediately overwrote it with a later time-stamp. But still, so what?
Nothing! Because the error file got created. Nothing is going to take any action--like sending emails--as a result of that files creation for another hour. From the OP:
if it has been encountered before and the time stamp is greater than an hour ago it will mail the admin
So the very worst affect of some other process creating the file instead of you, is that the sending of the email is delayed by the difference between the original time-stamp, and the new one. And that's just a few millseconds at most.
#! perl -slw
use Time::HiRes qw[ time ];
use threads qw[ stack_size 4096 ];
my $file = 'theFile';
async{ 1 until -e $file; }->detach for 1 .. 300;
sleep 3;
my @times = time;
unless( -e $file ) {
push @times, time;
open FILE, '>', $file or die "$file : $!";
push @times, time;
close FILE;
}
push @times, time;
print for @times;
unlink $file;
__END__
[20:51:05.40] C:\test>junk49
1285789900.703
1285789900.87509
1285789901.02394
1285789901.324
With 300 clients stating theFile (in a directory containing 1000 files), the window of opportunity for this irrelevant race condition is all of 300 milliseconds.
And then only if the time-stamp resolution of the file-system is sufficient to actually discern the difference, which is unlikely.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|