如何使用Perl的系统调用生成独立线程? [英] How can I use Perl's system call to spawn independent threads?

查看:52
本文介绍了如何使用Perl的系统调用生成独立线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用其他Perl脚本,以便从主要的Perl脚本执行竞争测试.

I would like to call other Perl scripts in order to perform a contention test from with a main Perl script.

类似的功能目前有效:

system("perl 1.pl");
system("perl 2.pl");
exit;

但是,我想将它们作为同时运行的独立线程来开始.

However, I would like to kick these off as independent threads running at the same time.

我尝试根据我的Google搜索,执行以下操作:

I tried, based on my Google searches, doing something like this:

system(1, "perl 1.pl");
system(1, "perl 2.pl");
exit;

那是行不通的.主脚本立即存在,这很好,但是我想要生成的基础线程不会启动.我想知道是否还有其他事情要做,或者其他人是否做过这样的事情.

That doesn't work. The main script exists immediately, which is fine, but the underlying threads I want to spawn don't get kicked off. I was wondering if there was something else I have to do or if anyone else has done something like this.

非常感谢您提前提供帮助.

Thanks for any help in advance.

推荐答案

use threads;
$thr1 = threads->create('msc', 'perl 1.pl');
$thr2 = threads->create('msc', 'perl 2.pl');

$thr1->join();
$thr2->join();

sub msc{ ## make system call
  system( @_ );
}

这将等待两者完成执行后再退出.我猜这是您最初提出的问题想要的,对吗?如果不能随意发表评论并编辑您的帖子以更好地解释它,我将再试一次.

This will wait for both to finish executing before the it will exit. I'm guessing this is what you want from your original question, right? If not feel free to drop a comment and edit your post to explain it better, and I'll try again.

这篇关于如何使用Perl的系统调用生成独立线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆