[英]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
$
眼鏡:
初步印象:
我認為當自定義信號處理程序獲取控制權時會出現問題。 這會以某種方式阻止創建下一個線程,從而導致段錯誤。
Perl的默認SIGINT處理程序是否運行特殊代碼以安全地結束線程創建的評估? 如果是這樣,我想解決方案是將copypasta引入自定義處理程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.