Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 如何在perl脚本中有条件地使用线程?_Multithreading_Perl - Fatal编程技术网

Multithreading 如何在perl脚本中有条件地使用线程?

Multithreading 如何在perl脚本中有条件地使用线程?,multithreading,perl,Multithreading,Perl,我开发了一个perl脚本,它运行在具有不同perl版本的主机上,有时使用线程编译,有时不使用线程 我有一个 use if $Config{"useithreads"}, "threads"; 我所有特定于线程的代码都有类似的条件 然而,在编译阶段,perl仍然会阻塞threads::all、threads::running等 我如何确定我的脚本同时在线程和非线程perl上运行 [ worr on worr-mn1 ] ( manage_usr_local_admin ) % perl -c

我开发了一个perl脚本,它运行在具有不同perl版本的主机上,有时使用线程编译,有时不使用线程

我有一个

use if $Config{"useithreads"}, "threads";
我所有特定于线程的代码都有类似的条件

然而,在编译阶段,perl仍然会阻塞threads::all、threads::running等

我如何确定我的脚本同时在线程和非线程perl上运行

 [ worr on worr-mn1 ] ( manage_usr_local_admin ) % perl -c acct_mgr_ng.pl
Bareword "threads::joinable" not allowed while "strict subs" in use at acct_mgr_ng.pl line 117.
BEGIN not safe after errors--compilation aborted at acct_mgr_ng.pl line 541.

use
语句在编译时解析。您希望使用
require
或在运行时有条件地拉入模块

像这样的方法应该会奏效:

use Module::Load ();
if($Config{'useithreads'}) {
    Module::Load::load("threads");
}

加载线程时,perl知道
threads::all
(和friends)是一个子程序调用,即使没有括号或
&
;由于线程可能不会被加载,所以只需用括号显式调用它:
threads::all()

如果$Config{useithreads},则需要在BEGIN块中使用线程,而不是使用它。显示“阻塞”看起来像什么我接受了@ysth的建议并使用了if,但是,在非线程机器上查找threads::all、threads::running等符号时,编译仍然失败。如何失败?让我们看看会发生什么!向我们展示使用threads::all的代码,etcI更新了我的问题以反映@ysth的更改并显示编译output@worr,我们需要查看产生错误的代码,而不仅仅是错误输出。更好:我们需要能够运行产生错误的演示代码。