One method is to use a shared variable as a flag to indicate that the background thread shoudl die. This requires that yo arrange for the background thread to check the flag periodically.
Another (better) option, if your OS is *nix, would be to look at liz's Thread::Signal package.
If your OS is Win32, then you could look at using Win32::API to gain access to the native OS call, TerminateThread(). However, to use this you need to gain access to the native thread handle which the threads API does not provide accesss to. There is a native API GetCurrentThreadId(), which will return the handle, but this must be called from the thread that you want to kill. So, you would have to obtain the native thread handle at the start of the background thread and save it to a shared variable so that the foreground thread can access it when it is time to terminate the thread.
Note: This would kill the thread in mid-flow, which is crude and not very "structured". Having the backgound thread periodically check a flag and exit gracefully is a better idea.
In reply to Re: Perl threads - telling them urgent stuff
by BrowserUk
in thread Perl threads - telling them urgent stuff
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |