in reply to Perl threads - telling them urgent stuff
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Perl threads - telling them urgent stuff
by pg (Canon) on Oct 20, 2003 at 00:36 UTC | |
by liz (Monsignor) on Oct 20, 2003 at 08:18 UTC | |
by BrowserUk (Patriarch) on Oct 20, 2003 at 00:45 UTC | |
by pg (Canon) on Oct 20, 2003 at 00:54 UTC | |
by BrowserUk (Patriarch) on Oct 20, 2003 at 01:19 UTC | |
by pg (Canon) on Oct 20, 2003 at 01:28 UTC | |
|