Yes, there are probably too many locks.

When I wrote this module some time ago I had to struggle with deadlocks.
So I finished with locking all variables always in the same order,
also in mind it would be easier to insert new functions into the code.

When the whole thing worked, I didn't mind to clean up..

At the place you mentioned: Do you mean cond_wait would also unlock ${$self->{poolcount}} or that locking ${$self->{poolcount}} is simply unneccessary ?
I didn't trie so much to have few locks, would you say that a lock is big penalty ?

I used the hash $self everywhere because I had in mind to be able to have more than one threadpool in an script.

You are however wrong about the creating of the threads,
the module doesn't destroy any thread at all.
Instead it creates up to maxthread threads and puts the work recieved with enqueue() onto a queue.
The threads pull in T_thread() the work of the queue.

I wrote this module, because I had some problems with growing memory of long running scripts, due to creating and destroying threads.

The OP's code..
The only thing I've changed has been the small delay (select undef,undef,undef,0.2;).
Since the OP didn't say exactly what he tries to do and where all the data should go, I didn't had a closer look, instead I really did copy'n paste.

I've just been curious whether I could replace Thread::Pool with my module,
since this worked without problems I thought my implementation could be helpful.
There's also the point that the feedback, especially yours, helps me improve my code.

So, no, I don't feel you would be negative.

In reply to Re^3: Threads and LWP::UserAgent question by misc
in thread Threads and LWP::UserAgent question by gatito

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.