in reply to Possible bug with threads

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));
}

Replies are listed 'Best First'.
Re: Re: Possible bug with threads
by znu (Acolyte) on Dec 21, 2002 at 07:32 UTC
    I don't understand why your saying i only created one child thread from the beginning to end!?!? If what you're saying is correct, and ive got $workers = 1, then when i launch the 1st thread, and it never quits, threads->list should always contain it's tid, therefore no more threads should be created and it should just sit there after showing: Starting workerPool... creating new threads ---I am thread 1! BUT, on my machine it doesnt, it goes on to print "I am thread X.. blah" where X goes from 1 till roughly 1020. Why?? And why does it get to around 1020 and then just hang?? confused :-/ Many thanks! P.S more info on what i'm trying to do is given in my reply to submersible_toaster (the url)