#! perl -slw use strict; use threads; my @t = map async( sub { my $tid = threads->tid; my $worktime = shift; print "Thread $tid started with a worktime of $worktime"; eval { local $SIG{ ALRM } = sub { die 'times up' }; alarm 10; ## simulate doing work here sleep $worktime; print "Thread $tid: all done"; }; print "Thread $tid ended ", $@ ? " with error: $@" : 'normally'; }, 2*$_ + $ARGV[ 0 ] ), 1 .. 4; $_->join for @t; __END__ C:\test>junk78 5 Thread 1 started with a worktime of 7 Thread 2 started with a worktime of 9 Thread 3 started with a worktime of 11 Thread 4 started with a worktime of 13 Thread 1: all done Thread 1 ended normally Thread 2: all done Thread 2 ended normally Thread 4 ended with error: times up at C:\test\junk78.pl line 10. Thread 3 ended with error: times up at C:\test\junk78.pl line 10.