in reply to END block not excuting when thread interrupted

Why not add a signal handler for $SIG{INT} to the parent? For example, if I add this:
sub sigint { die "Dying."; } $SIG{INT} = \&sigint;
to your program up at the top, everything exits fine on SIGINT, and the end block is executed:
$ perl test.pl processing sleep(0) in thread 1 processing sleep(1) in thread 1 processing sleep(3) in thread 3 processing sleep(0) in thread 4 processing sleep(2) in thread 4 processing sleep(4) in thread 2 processing sleep(0) in thread 1 processing sleep(3) in thread 1 processing sleep(4) in thread 4 processing sleep(5) in thread 3 <C-c> Dying. at test.pl line 25. END block executed A thread exited while 3 threads were running.
You probably want to do something other than die(), but same idea. SIGCHLD (ignored by default) will catch child deaths, if that's what you wanted originally.

Replies are listed 'Best First'.
Re^2: END block not excuting when thread interrupted
by iankorf (Acolyte) on Jul 10, 2006 at 01:19 UTC
    Many thanks jrockway and BrowserUk.