我正在學習Perl的多線程。我的代碼:這爲什麼打印12次?
use warnings;
use threads;
use threads::shared;
$howmany = 10;
$threads = 5;
$to = int($howmany/$threads);
for (0 .. $threads) {$trl[$_] = threads->create(\&main, $_);}
for (@trl) {$_->join;}
sub main {
for (1 .. $to) {
print "test\n";
}
}
exit(0);
我想要打印的字測試$howmany
次$threads
線程。 此代碼打印測試 12次。哪裏有問題?
沒錯!我有幾個小時我無法理解這個問題。非常感謝你。 – Anton 2011-06-03 00:40:49