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.
RIP an inspiration; A true Folk's Guy

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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.