PERL实现多线程的一些demo程序
以前学perl时候的一些笔记。主要是perl来写多线程的程序,整理一下 1 #!/bin/perl use threads; use threads::shared; # 涉及到一些进程间变量的共享,用这个模块 my $process = 4; my $child_num = 0; print $threads::VERSION.chr(10); while (1) { if ($child_num < $process){ my $params = $child_num.':..........'; my $thr = threads->create(\&start_thread, $params); $child_num ++; } #foreach my $t(threads->list()){ foreach my $t(threads->list(threads::joinable)){ $t->join(); } # all tasks done and no running child, then exit if ($child_num==4){ exit; } } sub start_thread(){ # do actually task here my $param = shift; print $param.chr(10); } 2 my $maxchild