Your program will exit early, as you never wait for the threads to end. I've ripped out all the logfile creation, the batch file reading and usage message, and the following program works just like I expect it to, "processing" 10 stores in parallel:
#!/opt/perl-5.8.8/bin/perl -w # # use strict; use Getopt::Long; use threads; use threads::shared; use Thread::Queue; require Data::Dumper; ######## Do not modify if you do not know what you are doing!!! can de +grade performance!! ######## my $max_thread_count = 10; ###################################################################### +############################ my $version = "0.1_01"; my @stores = sort map { sprintf 'store%03d', $_ } 0..$max_thread_count +*2; my $thread; my $thread_list; my $tid; sub writeLog { print "$_[0]\n"; } my $jobs = Thread::Queue->new(@stores); # read work file sub processWF { my @lines = ( 'perl -wle "print q(storeplaceholder stage 1);sleep(rand(10));pr +int q(storeplaceholder stage 1 done)"', 'perl -wle "print q(storeplaceholder stage 2);sleep(rand(10));pr +int q(storeplaceholder stage 2 done)"', ); while (defined (my $item = $jobs->dequeue)) { writeLog("Launching $item"); foreach my $line (@lines) { $line =~ s/storeplaceholder/$item/g; #print "running: $line\n"; system($line) == 0 or warn "Couldn't launch [$line]: $!/$?"; } } } $jobs->enqueue(undef) for 1..$max_thread_count; my @workers = map { threads->create( \&processWF ) } 1..$max_thread_co +unt; $_->join() for @workers;
Consider reducing your programs to the mininmum needed code to reproduce the program while still retaining a full, ready-to-run program. This makes it much easier for us to reproduce the problem and help you. Also, in that process, I usually find the error myself, without posting here.
In reply to Re^11: Help needed with regard to arrays
by Corion
in thread Help needed with regard to arrays
by theknightsofni
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |