#/usr/bin/perl -w use strict; use warnings; use threads; use threads::shared; my @thrList; my $count=1; share $count; $SIG{INT} = \&catch_CtrlC; &main; sub main { my $counter = 3; while($counter) { $counter--; my $thrHandle = threads->create(\&thrdfun); push @thrList, $thrHandle; } print " waiting \n"; foreach(@thrList){ $_->join(); } } sub thrdfun { $SIG{INT} = \&trExit; print "thrdfun: $count \n"; $count++; while(1){ } exit; } sub trExit { print " exit \n"; threads->exit(); } sub catch_CtrlC { print " catch_CtrlC \n"; foreach(@thrList){ $_->kill("INT"); } exit; }