linux - Why does my threaded Perl script segfault? -


i'm writing curses script requires cleanup after processing sigint in order return terminal original status.

i segfault when signal handler enabled.

for support's sake, removed curses code boil problem down.

code:

#!/usr/bin/env perl  use strict; use warnings; use threads;  sub cleanup { exit 0; }  sub run { while (1) {} }  # comment line , problem disappears $sig{int} = \&cleanup;  foreach $i (1..100) {     print "creating thread\n";      $t = threads->create(\&run);      print "created thread\n"; }  while (1) { print "looping\n"; } 

sample error trace (segfaults 90% of time):

$ ./threadtest.perl  ...  creating thread creating thread detaching thread detaching thread creating thread ^csegmentation fault  $ 

specs:

  • threads 1.72
  • archname ""
  • os ""
  • perl 5.10.1 (came debian) debian
  • 6 squeeze

initial impression:

i think problem occurs when custom signal handler grabs control. somehow prevents next thread being created, resulting in segfault.

does perl's default sigint handler run special code safely end evaluation of thread creation? if so, imagine solution copypasta custom handler.

the revision history threads module contains:

1.73 mon jun  8 13:17:04 2009 - signal handling during thread creation/destruction (john wright) - upgraded ppport.h devel::ppport 3.17 

which suggests there known problem signal handling during thread creation , destruction in versions earlier 1.73. upgrade threads module.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -