What do you mean by 1021 threads? From the beginning to the end (if there is an end), you only created one child thread.

Just as what I said in my reply to your first post, the worker thread you created will never ever quit, so your worker pool is full right after you created the first thread, and it stays full, therefore no space left for any new threads, in your worker pool.

I modified your printing a little bit, to show you that it does not work as you expected or described: ( I didn't make any logic change, just prints)
use threads; use strict;
# I added this to make sure we see all printing on time $| ++;
# constants my $workers = 1; #number of simultaneous workers workerPool(); sub list_threads { my @threads = threads->list; print "--threads i know of: -----\n"; for my $t (@threads) { print $t->tid."\n"; } print "--------------------------"; } # sub which maintains a set number of simultaneous threads sub workerPool { print "Starting workerPool...\n"; my $count = 0; my @running_threads = (); while (1) { @running_threads = threads->list; if (scalar(@running_threads) < $workers) {
#I added this, and it only shows ONCE print "creating new threads\n";
# add a new worker $count++; my $thread = threads->new(\&worker, $count); }
# I commented out this, with this flushing the output all the +time, I cannot see anything useful #list_threads();
} } # this sub represents a thread sub worker { my $thread_num = $_[0]; print "---I am thread $thread_num!\n";
#this is simply a lie print "+++Thread $thread_num gone!\n"; #this hangs this worker thread itself eval(((threads->self)->join));
}

In reply to Re: Possible bug with threads by pg
in thread Possible bug with threads by znu

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.