in reply to Re^2: about THREAD SIGNALLING
in thread about THREAD SIGNALLING

Just remember that sub catch_CtrlC {} and SIG{'INT'} = \&catch_CtrlC; must both be included in each thread that you want to SIGINT out of.
#/usr/bin/perl use strict; use warnings; use threads; use threads::shared; my @thrList; my $count = 1; share $count; my $counter = 3; while ($counter) { $counter--; my $thrHandle = threads->create( \&thrdfun ); push @thrList, $thrHandle; } foreach (@thrList) { $_->join(); } sub thrdfun { sub catch_CtrlC { $_->kill('TERM'); } $SIG{'INT'} = \&catch_CtrlC; print "thrdfun: $count \n"; $count++; while (1) { (); } exit; }

Replies are listed 'Best First'.
Re^4: about THREAD SIGNALLING
by anaconda_wly (Scribe) on Apr 23, 2013 at 08:44 UTC
    OK, I got the point. The thread sig handler should be defined inside the thread body, different from the process signal handler.