Re: Best Practice For Killing Thread?

[email protected] (Elizabeth Mattijsen)
Newsgroups perl.ithreads
Message-ID <p05111b05bbcc56d5f389@[192.168.56.2]>
At 10:39 -0800 11/3/03, Steve Schein wrote:
>I am using Perl v5.8 w/ithreads and have a thread which is a UDP
>listening socket that listens for messages in a perpetual read loop.
>There are times that this socket needs to be broken down along with the
>corresponding thread.
>What is the current best practice for killing a single thread with
>ithreads?

The best way would be to use a shared array or shared hash (keyed to 
thread id) with a flag being set.  The thread will then need to check 
that flag every so often and shut itself down when the flag is set.


>If the answer is to kill the process, please suggest ways to obtain the
>pid.

Threads only have pids on Linux.  This is used by Thread::Signal (my 
version, from CPAN), which provides an API for sending signals to 
threads.  However, an exit() from a thread will stop all threads.  If 
that's the way you want to do it, you'd also need Thread::Exit (also 
by me, from CPAN).

You may also need to switch off safe signal behaviour if a thread is 
stuck in some kind of network operation.


Hope this helps.


Liz
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.