- or download this
use threads;
use strict;
- or download this
# I added this to make sure we see all printing on time
$| ++;
- or download this
# constants
my $workers = 1; #number of simultaneous workers
...
while (1) {
@running_threads = threads->list;
if (scalar(@running_threads) < $workers) {
- or download this
#I added this, and it only shows ONCE
print "creating new threads\n";
- or download this
# add a new worker
$count++;
my $thread = threads->new(\&worker, $count);
}
- or download this
# I commented out this, with this flushing the output all the
+time, I cannot see anything useful
#list_threads();
- or download this
}
}
...
sub worker {
my $thread_num = $_[0];
print "---I am thread $thread_num!\n";
- or download this
#this is simply a lie
print "+++Thread $thread_num gone!\n";
#this hangs this worker thread itself
eval(((threads->self)->join));
- or download this
}