You sure this works under windows? > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Tom Pollard > Sent: Friday, August 26, 2005 2:17 AM > To: ajpeck > Cc: Perl Win32 mail list > Subject: Re: [threads] Forced termination > > > On Thu, 25 Aug 2005, ajpeck wrote: > > Is there a way to forcibly terminate a thread after a specified time > > regardless if the thread is finished executing. > > The standard eval{}-timeout technique apparently works well > for threads. That is, wrap the code that might hang for 5 min > in an eval{} block and use an alarm to time it out, e.g. > > eval { > local %SIG{ALRM} = { die "TIMEOUT\n"; }; > alarm 5; > <...your code here...> > alarm 0; > } > giveup() if $@ =~ /^TIMEOUT/; > > ...where giveup() does whatver you need to do to exit from the thread > prematurely. In general, threads and signals are awkward to > use together, > but this particular idiom has been unproblematic for us in > our threaded > perl apps. > > TomP > > > I have threads which > > call certain network functions that have very long hard > coded timeouts, > > such as 5 mins. A no response of 5 secs is sufficient for > me to know > > that there is a problem and the nature of it is not needed (device > > switched off, network break, etc). These threads only write > out a status > > result (threads::shared variable) at the very end of the thread > > execution, thus terminating the thread early from within the parent > > thread and with no result written is good enough for me to > know that > > there is a problem. > > > > Is there a way to impliment timed thread termination, if so I would > > appreciate it very much for a very simple example. > > -------------------------------------------------------------- > ----------- > Tom Pollard > [EMAIL PROTECTED] > Schrodinger, Inc. 646-366-9555 x102 > -------------------------------------------------------------- > ----------- > > > _______________________________________________ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs >
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs