Why is my streaming Perl script segfault?

I am writing a curses script that needs to be cleaned after SIGINT processing in order to return the terminal to its original state.

I get segfault when the signal handler is on.

For support, I removed all the curse code to minimize the problem.

the code:

#!/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"; } 

Error tracing example (segfaults 90% of the time):

 $ ./threadtest.perl ... Creating this thread Creating that thread Detaching this thread Detaching that thread Creating this thread ^CSegmentation fault $ 

Specifications:

  • Themes 1.72
  • archname ""
  • os ""
  • Perl 5.10.1 (shipped with Debian) Debian
  • 6 squeeze

Initial impression:

I think the problem arises when the user signal handler takes control. This somehow prevents the creation of the next thread, which leads to segfault.

Does Perl execute the SIGINT handler by default with special code to safely complete the thread creation evaluation? If so, I suggest that the solution is to copy pasta to a custom handler.

+6
multithreading segmentation-fault linux perl
source share
1 answer

The change history for the threads module contains:

 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 

which indicates that there was a known problem with signal processing when creating and destroying threads in versions prior to 1.73. Update the threads module.

+4
source share

All Articles