Creating and destroying hundreds of threads, especially if they are short lived) is (almost) never the right way to do things. This is doubly true for perl's iThreads on win32 which are far heavier that native threads.

Re-jigging your app so that you start a pool of threads and re-use them once they have completed their last task is often quite easy to do.

Take a look at Thread::Queue for a simple mechanism for supplying work to your thread pool. Essentially all that is needed is a wrapper around your blast_thread sub that takes an item of work off of a shared queue and processes it, then loops back and gets another. When the queue is empty, the thread can die. If you need to return values from the threads back to your main process, then a second queue written by the threads and read in a loop by the main process once it has started the thread pool is simple mechanism to put in place.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

In reply to Re: A Memory Leak in Perl iThreads? by BrowserUk
in thread A Memory Leak in Perl iThreads? 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.