Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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
    [james28909]: how come it is so easy for me to not care what others think while others will mute themselves because they are scare they will be called ignorant or stupid
    [james28909]: do you relize how shrodinger felt when he was describing the quantum world? what about neils bohr?
    [holli]: it's probably the autist in you. I am like that too, no fucks given about what others think about me
    james28909 checks, yep... htere are no fucks to give
    [james28909]: another thing i am sick of is hurting others feelings
    [1nickt]: james28909 You lost me a bit when you said "show me evolution from intelligence to ignorance". I guess we would have to define the terms, but as I look around at my species and how we are destroying our habitat ...
    [james28909]: seems like a person cant even have a belief without hurting someones feelings. i never said my way is the only way. i just said i have pretty good scientific evidence, and then asked for opposing side to present evidence
    [james28909]: was downvoted and left without a reply. go figure
    [holli]: but then you DO give a fuck
    [1nickt]: I don;t think beliefs should be down-voted, just behaviours.

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (14)
    As of 2017-12-15 14:26 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (433 votes). Check out past polls.