2 ###APPNAME: exec_threads
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Wed Mar 26 15:10:05 2008
6 ###APPDESC: execute cmds using threads
7 ###APPUSAGE: (Number of threads)
8 ###APPEXAMPLE: cat cmd.lst | exec_threads 3
13 $ARGV[0]="-h" unless(@ARGV);
15 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
19 die("Number must greater than 0\n") unless($max>0);
24 print STDERR
"\n[Thread $idx]",@_,"\n";
35 return $idx unless(defined($t));
54 # print "\n[Thread:",($idx+1),"] End\n";
55 $ths[$idx]=threads
->create(\
&process
,$idx,$cmd);
59 my $hnd=threads
->create(\
&process
,$idx,$cmd);
62 # print "\n[Thread:",($idx+1),"] Start: $cmd\n";
63 # print STDERR "\n\n[T",($idx+1),"]:$cmd\n";
66 for(my $i=0;$i<@ths;$i++) {
67 next unless($ths[$i]);
68 next unless($ths[$i]->is_running() or $ths[$i]->is_joinable());
70 # print "\n[Thread:",($i+1),"] End\n";