My opinion is that no one should use Threads::Pool -- it is rubbish.

Rather than hard-wiring the allocation of the hashes to your threads, make the array holding the hash references shared (if it isn't already). Then create a Thread::Queue. Push the indices (0..9 or 0..2499 etc.) onto that Queue. Have your threads read the next index off the Queue and process the associated hash.

If one thread gets a particularly large one to process, the other threads will continue to read the next index from the queue as soon as they are free, and so the whole thing becomes self-balancing.

As the hashrefs are in an array, you could avoid the queue by placing the highest index in a shared scalar and have each thread: lock the scalar; read its value; decrement it; unlock it; process the hashref indexed by the value read.

But honestly, the Queue mechanism incurs very little overhead and works for any kind of ticketing mechanism, so it probably easier to stick with it.


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.

In reply to Re: Efficiency of threads::shared versus Thread::Pool by BrowserUk
in thread Efficiency of threads::shared versus Thread::Pool by traceyfreitas

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.