【发布时间】:2011-06-29 15:05:27
【问题描述】:
我正在编写一个 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 thread\n";
my $t = threads->create(\&run);
print "Created that thread\n";
}
while (1) { print "Looping\n"; }
示例错误跟踪(90% 的时间段错误):
$ ./threadtest.perl
...
Creating this thread
Creating that thread
Detaching this thread
Detaching that thread
Creating this thread
^CSegmentation fault
$
规格:
- 线程 1.72
- archname ""
- 操作系统“”
- Perl 5.10.1(Debian 自带)Debian
- 6 挤压
初步印象:
我认为当自定义信号处理程序获取控制权时会出现问题。这会以某种方式阻止创建下一个线程,从而导致段错误。
Perl 的默认 SIGINT 处理程序是否运行特殊代码来安全地结束对线程创建的评估?如果是这样,我想解决方案是将pasta复制到自定义处理程序中。
【问题讨论】:
-
以下 sn-p 是否会导致段错误:perl -e "sub M::DESTROY; bless {}, M;" (如果是这样,您需要查看是否有更新的 5.10.1)——您的脚本在 5.10.1 上运行良好,没有该错误
-
在 Perl 5.10.1 上对我来说没有段错误。你的系统规格是什么?
-
mcandre:代码在我的 Perl 5.12.3 中运行良好。
-
@Alan 好。有人可以验证 Debian(存储库没有 5.12.x)、Mac OS X(MacPorts 有 5.12.2)和 Windows(ActiveState Perl 5.12.3)吗?
-
mcandre:在 Perl 5.10.1 (Ubuntu 10.10) 中工作。
标签: linux multithreading perl segmentation-fault