#!/usr/bin/perl use strict; use warnings; use threads; my $thread1 = threads::async { my $sleep = int(rand() * 5); print("Thread sleeping $sleep seconds\n"); sleep($sleep); return($sleep); }; sleep(2); if( $thread1->is_running() ) { print("Alert! That thread took more than 2 seconds!\n"); } else { print("No problem\n"); } print "Thread eventually returned ".$thread1->join()."\n";