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