我很好奇多线程是什么。我已经听到了在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