Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
1. You are opening a lock to a semaphore file (lock.tmp).
2. Once that lock is obtained you are opening an output file (somefile$_.tmp).
3. You unlock/close your semaphore file.
4. You write to somefile$_.tmp
5. You close somefile$_.tmp.
6. You copy from your tmp file to a new file.
Steps 4, 5, and 6 are unprotected.
I knew that if lock extended to other steps it works, but I could not understand why.

The thing is: When I open file on step (2), I write to it in step (4). But steps (4) and (5) are actually protected. Steps (4) and (5) is performed only if that process was the one who created file. Otherwise step is skipped. (and this was intentional - I was trying to minimize lock time which was important)

Notice "if ($f)"
if ($f) { print ($f "x") for (1..40_000_000); close $f; }
Problem was that step (6) unprotected. And this assertion was wrong:
die if -s $filename != -s $newfilename;
Correct assertion would be:
die if 40_000_000 != -s $newfilename;
i.e. when data copied, file could be in the middle of creation by another process. so in the end I see:
correct size of $filename
wrong size of $newfilename
assertion passed: if -s $filename != -s $newfilename;

Thank you! I'll mark post as SOLVED

In reply to Re^2: Strange IO + concurrency issue by vsespb
in thread [SOLVED] Strange IO + concurrency issue by vsespb

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2015-11-27 16:57 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (731 votes), past polls