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.
multithreading segmentation-fault linux perl
mcandre
source share