Re: Killing a thread

[email protected] ("Jerry D. Hedden") Wed, 29 Sep 2010 11:11:20 -0400
Newsgroups perl.ithreads
Message-ID <[email protected]>
To my knowledge, if the thread hangs on a system call, then you'll
need to do something similar to what was suggested by the previous
poster.

On Wed, Sep 29, 2010 at 10:47, Danny Wong (dannwong) <[email protected]> w=
rote:
> Hi Jerry,
> =A0 =A0 =A0 =A0Is there an example you or someone can provide, if the thr=
ead is
> hanging, I would just like the thread to "return failure or timeout" and
> ignore the system call. Let the system call hang and I'll clean it up
> afterwards at the very end of the script.
>
> Sincerely yours,
> Danny H. Wong
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Jerry
> D. Hedden
> Sent: Wednesday, September 29, 2010 5:47 AM
> To: Danny Wong (dannwong)
> Cc: [email protected]
> Subject: Re: Killing a thread
>
> Danny Wong wrote:
>> Here is my situation. I started, say 10 threads, executing
>> some command, 1 or 2 of them is hanging for over 2 hours.
>> I want to put in some logic that if the thread run time
>> passes an hour threshold kill that thread or return and
>> fail the thread. Any ideas on how I can accomplish this
>> task? Thanks.
>
> This problem is addressed in the 'examples/pool.pl' file in
> the 'threads' distribution on CPAN. =A0From the POD (note the
> third bullet):
>
> =A0 =A0NAME
> =A0 =A0 =A0 =A0pool.pl - Simple 'threads' example
>
> =A0 =A0DESCRIPTION
> =A0 =A0 =A0 =A0A simplistic example illustrating the following:
> =A0 =A0 =A0 =A0* =A0 Management of a pool of threads
> =A0 =A0 =A0 =A0* =A0 Communication between threads using queues
> =A0 =A0 =A0 =A0* =A0 Timing out and cancelling threads
> =A0 =A0 =A0 =A0* =A0 Interrupting a threaded program
> =A0 =A0 =A0 =A0* =A0 Cleaning up threads before terminating
>
> However, if the 'hung' threads are stuck on some system
> call, then the above will not work because of Perl's "safe
> signals". =A0You'll need to read the section called "Deferred
> Signals (Safe Signals)" in "perldoc perlipc".
>