#!/usr/bin/env perl use strict; use warnings; use threads; sub worker { print "Worker thread started.\n"; while(1){} } my $thread = threads->create(\&worker); print "Setting alarm.\n"; $SIG{ALRM} = sub { die "Alarm!\n" }; alarm 2; print "Check join\n"; while (threads::running) { $_->join for threads->list(threads::joinable); } #### #!/usr/bin/env perl use strict; use warnings; use threads; use constant TIMEOUT => 2; sub worker { print "Worker thread started.\n"; while(1){} } my $thread = threads->create(\&worker); print "Check join\n"; while (1) { $_->join for threads->list(threads::joinable); last unless threads->list(threads::running); die "Alarm!\n" if time - $^T > TIMEOUT; select(undef,undef,undef,0.5); }