Thanks for your answer. That tutorial was one of the ones I had already read.

I admit the code I posted wasn't very good. I tried to simplify my code, but the result didn't run by itself.

Using a semaphore helps, but there is still a lot of garbled output.

I think part of the problem may be NFS, as mentioned in the File Locking tutorial. The output file on which I place the lock is in my home directory, which is mounted on all the cluster computers.

I tried using File::NFSLock and File::SharedNFSLock, and ran some tests. Sometimes one module does better, sometimes the other, but none achieves 100%. In the best case, at least 100 out of 22000 lines are still jumbled together.

So I guess I will have to go back to my previous approach, in which I printed the data to a bunch of files containing four lines each, and then postprocess the whole thing by concatenating them, sorting and grep'ping for the right lines to separate the output into the four desired output files.

Oh well. At least I learned something in the process :-)


In reply to Re: Threads and output files (locking) by Anonymous Monk
in thread Threads and output files (locking) by Anonymous Monk

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.