PodMaster is right. You cannot share objects across threads.

The answer may be to create a new instance of the scripting object in each thread. I haven't tried this, so you'll have to suck it and see, but I don't see any reason why it wouldn't work.

As for the free to wrong pool. Do you get these messages when the program closes down?

One note of caution. Multi-threading directory scans, especially if the all (or many of) the paths are on the same physical drive, will have rapidly diminishing returns in terms of performance. Each time a context switch occurs--ie. one thread gets switch for another by the scheduler--then the drive head will have to move to another part of the disk to scan the path for that thread, and then move somewhere else as the next thread takes its turn.

Moving heads between tracks is hugely more expensive than just waiting for the disk to roll passed the head, so the penalty can outweight the benefits. Additionally, reading another part of the disc can cause data already read from the disc into cache but not yet supplied to the program to be invalidated and discarded so that when the program does get around to asking for that information it has to be re-read.

Don't let that put you off trying, but don't be surprised if you find that whilst two or three threads improves performance that 4 starts to diminish it, and 5 really slows things up.

NOTE: Those numbers are just examples. The breakpoint could 6 or 8 or 2. Even just 1, but normally not.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: Starting multi-threading by BrowserUk
in thread Starting multi-threading by blackadder

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.