use strict; use threads; use threads::shared; my $inthread : shared; # the exit handler (END block) is never called when a thread performs an exit() # using a lower main sleep time will result in a normal exit of the main thread. my $threadsleeptime : shared = 2; my $mainsleeptime = 5; my $thread = async { eval { $inthread = 1; sleep($threadsleeptime); print "Sleep in thread finished\n"; die('abnormal exit'); }; if( $@ =~ /^abnormal exit/ ) { ## do cleanup print "doing cleanup in thread\n"; } } sleep($mainsleeptime); print "Sleep in main finished\n"; $thread->join if ($thread); print "End of main program\n"; __END__ C:\test>junk29 Sleep in main finished Sleep in thread finished doing cleanup in thread End of main program