- 論壇徽章:
- 0
|
小弟初學(xué)perl的多線程,邊看大駱駝邊寫(xiě)了幾行試試,發(fā)現(xiàn)調(diào)用join后子線程仍然繼續(xù)運(yùn)行?請(qǐng)高手指點(diǎn)一下!注:win32系統(tǒng)
是否對(duì)join理解有誤?還是代碼問(wèn)題?
use Thread;
print "新建線程!\n";
my $t=Thread->new(\&hello,,);
sleep(10);
print"收割線程!\n";
my $result=$t->join();
print"$result\n";
print"testing ok\n";
sub hello
{ my $sum=0;
while(1)
{
sleep(1);
print"$sum hello,first thread program!\n";
$sum++;
if($sum>10){last;}
}
}
執(zhí)行結(jié)果如下:
新建線程!
0 hello,first thread program!
1 hello,first thread program!
2 hello,first thread program!
3 hello,first thread program!
4 hello,first thread program!
5 hello,first thread program!
6 hello,first thread program!
7 hello,first thread program!
8 hello,first thread program!
收割線程!
9 hello,first thread program!
10 hello,first thread program!
testing ok |
|