加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (https://www.0631zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

linux – 为什么我的线程Perl脚本会出现段错误?

发布时间:2021-01-12 00:07:30 所属栏目:Linux 来源:网络整理
导读:我正在编写一个curses脚本,它需要在处理SIGINT后进行清理,以便将终端恢复到原始状态. 启用信号处理程序时,我得到一个段错误. 为了支持,我删除了所有的curses代码以解决问题. 码: #!/usr/bin/env perluse strict;use warnings;use threads;sub cleanup { exi

我正在编写一个curses脚本,它需要在处理SIGINT后进行清理,以便将终端恢复到原始状态.

启用信号处理程序时,我得到一个段错误.

为了支持,我删除了所有的curses代码以解决问题.

码:

#!/usr/bin/env perl

use strict;
use warnings;
use threads;

sub cleanup { exit 0; }

sub run { while (1) {} }

# comment this line and the problem disappears
$SIG{INT} = &;cleanup;

foreach my $i (1..100) {
    print "Creating this threadn";

    my $t = threads->create(&;run);

    print "Created that threadn";
}

while (1) { print "Loopingn"; }

示例错误跟踪(90%的时间段为segfaults):

$./threadtest.perl

...

Creating this thread
Creating that thread
Detaching this thread
Detaching that thread
Creating this thread
^CSegmentation fault

$

眼镜:

>线程1.72
> archname“”
> os“”
> Perl 5.10.1(Debian附带)Debian
> 6挤压

初步印象:

我认为当自定义信号处理程序获取控制权时会出现问题.这会以某种方式阻止创建下一个线程,从而导致段错误.

Perl的默认SIGINT处理程序是否运行特殊代码以安全地结束线程创建的评估?如果是这样,我想解决方案是将copypasta引入自定义处理程序.

最佳答案 revision history for the threads module包含:

1.73 Mon Jun  8 13:17:04 2009
- Signal handling during thread creation/destruction (John Wright)
- Upgraded ppport.h to Devel::PPPort 3.17

这表明在早于1.73的版本中,在创建和销毁线程期间存在已知的信号处理问题.升级您的线程模块.

(编辑:威海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读