in reply to Re^4: avoiding a race (much ado)
in thread avoiding a race
I don't see how you justify that the race doesn't result in extra e-mails. I believe your analysis is mistaken there.
Hm. The window your "still racy" referred to, was the time between a failed stat, and open. Ie:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: avoiding a race (place snark here)
by tye (Sage) on Sep 29, 2010 at 20:53 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 21:17 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 21:10 UTC | |
by tye (Sage) on Sep 29, 2010 at 21:41 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2010 at 21:57 UTC |