znu has asked for the wisdom of the Perl Monks concerning the following question:
#!/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)); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Possible bug with threads
by pg (Canon) on Dec 20, 2002 at 05:29 UTC | |
by znu (Acolyte) on Dec 21, 2002 at 07:32 UTC | |
|
Re: Possible bug with threads
by submersible_toaster (Chaplain) on Dec 20, 2002 at 08:55 UTC | |
by znu (Acolyte) on Dec 21, 2002 at 07:23 UTC |