簡體   English   中英

為什么我的線程Perl腳本會出現段錯誤?

[英]Why does my threaded Perl script segfault?

我正在編寫一個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%的時間段為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引入自定義處理程序。

threads模塊修訂歷史記錄包含:

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的版本中,在創建和銷毀線程期間存在已知的信號處理問題。 升級您的threads模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM