我很好奇多線程是什麼。我已經聽到了在StackOverflow中收到的答案,但我不知道它是什麼,所以我的主要兩個問題是它是什麼以及我如何從中受益?什麼是多線程?
編輯:
好,因爲第一個問題並沒有真正得到我一直在尋找,我會與此去響應..
我從來沒有聽說過的「穿透」甚至在其他語言。這是我在互聯網上找到的一個例子:
#!/usr/bin/perl
use strict;
use warnings;
use threads;
use threads::shared;
print "Starting main program\n";
my @threads;
for (my $count = 1; $count <= 10; $count++) {
my $t = threads->new(\&sub1, $count);
push(@threads,$t);
}
foreach (@threads) {
my $num = $_->join;
print "done with $num\n";
}
print "End of main program\n";
sub sub1 {
my $num = shift;
print "started thread $num\n";
sleep $num;
print "done with thread $num\n";
return $num;
}
我似乎無法理解它在做什麼。任何人都可以照亮任何光明? 問候, 菲爾
您是否嘗試閱讀Wikipeadia - http://en.wikipedia.org/wiki/Multithreading? perl中有關於線程的一些特殊的東西,但總體思路與所有其他語言相同。 – 2010-09-23 15:41:46
線程安全年輕蚱蜢 – Chris 2010-09-23 15:54:09
您是否運行了Perl代碼,並觀察輸出? – 2010-09-23 16:28:24