我有简单的多线程站点检查器。 我试图在环txt文件打开这个目录用线程打开的perl队列文件
my @files = glob('*.txt');
foreach my $file(@files){
@sites=load_file($file);
$total_count = scalar(@sites);
for my $t (1..$threads) {
push @threads, threads->create(\&check, $t);#check- main subroutine
threads->create(\&stat)->join() if $t == $threads;#stat - realtime statistics(good/bads) sites
}
foreach my $t (@threads) {
$t->join();
}
}
但它仅适用于第一个文件和程序终止工作。 任何人都可以帮忙吗? 谢谢。
您是否使用严格;使用警告'? '@ threads'声明在哪里?为什么它不在外部循环中声明*?另外,我看不到线程和'@ sites'之间的任何交互。你知道['Thread :: Queue'](https://metacpan.org/module/Thread::Queue)吗? – amon
是的。因为这与问题无关。子程序检查使用@sites。 – Wolfgang
如果你不知道为什么你的程序不能正常工作,那么你不能说与问题相关的是什么。请发布您的完整代码。我在这个片段中根本看不到任何声明,我怀疑在其他地方对'@ sites','$ threads'或'@ threads'的处理不当。 – Borodin