$SIG{USR1} = sub {shutdown = 1;}; foreach my $functions_name (@func_arr){ #Start new thread my $t = threads->create (sub{ &$functions_name(@parameters); $SIG{KILL} = sub { print "\ngot to thread killer\n\n"; threads->exit(); }; print "\ngot to end of thread\n\n"; #$shutdown = 1; }); push(@threads,$t); } sleep until $shutdown; if (my @remain = threads->list(threads::running)) { foreach (@remain) { if ($_ != $$){ $_->kill('KILL')->detach; } } $shutdown = 0; testProcess::prc_kill_handler(); } print "All threads exited normally."; my $index=0; foreach my $thread (@threads) #wait for all threads untill the end and insert results to hash { $hash_results{$index}=$thread->join; $index++; } return %hash_results;