in reply to Efficiency of threads::shared versus Thread::Pool

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.
  • Comment on Re: Efficiency of threads::shared versus Thread::Pool