Hello again. This is driving me nuts, and i'm beginning to think it's a bug with threads. AFAIK the following code is correct and should continue to spawn 1 thread, wait until it's finished, spawn another, so on and so forth for all eternity. However, on my machine it spawns around 1021 or so threads and around there somewhere it begins to create threads that never return :-/ Could people please confirm that this is a problem, or modify the code so as to make it work (& also work with more than one $worker). Many thanks, Zoltan.
#!/usr/local/bin/perl use threads; use strict; # 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) { # add a new worker $count++; my $thread = threads->new(\&worker, $count); } list_threads(); } } # this sub represents a thread sub worker { my $thread_num = $_[0]; print "---I am thread $thread_num!\n"; print "+++Thread $thread_num gone!\n"; eval(((threads->self)->join)); }

In reply to 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.