If your machine does not have multiple processors, then all your threads will be sharing the time on the same processor, so there is no advantage. But, by using multiple threads, you incur the overhead of the threading support itself, so a net loss in throughput.

However, even if you have multiple processors, if your files all reside on the same drive, then by using multiple threads, you are causing the read heads to jump around all over the disk in order to try and supply the separate threads with data, and you are again incurring overhead not present with the single-threaded process.

The only way you will see benefit from threading this kind of IO-bound processing, is if you have multiple processors, and can arrange for files being read and/or written to reside on different, local disks. And note: different physical drives, not different logical partitions of the same drive. Even then, the spitting of the system filecache between different concurrent files is likely to hit the throughput more than any gains you might achieve.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Threads Doubt by BrowserUk
in thread Threads Doubt 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.