brycen has asked for the wisdom of the Perl Monks concerning the following question:
This code works great in perl 5.10.0, but does not run in 5.8.8. Is there a Monk who can advise how to achieve the same effect using the older Perl? The 5.8.8 in question has ithreads, not 5005threads (specifying use Thread gives ithreads):
The end goal is code that alerts if a thread (which will run some blocking I/O) runs too slowly or too long.
This is a reformulated version of 777702#!/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";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $thread->is_running() in perl 5.8.8 - catching slow threads
by ikegami (Patriarch) on Jul 08, 2009 at 20:23 UTC | |
Re: $thread->is_running() in perl 5.8.8 - catching slow threads
by BrowserUk (Patriarch) on Jul 08, 2009 at 21:03 UTC |
Back to
Seekers of Perl Wisdom