Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
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.


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.

In reply to Re^5: avoiding a race (the ado, you do, so well:) by BrowserUk
in thread avoiding a race by westy032001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.