Re: How to kill an overlapped thread ?
Posted by Chris Uppal-3 on Feb 25, 2005; 8:55am
URL: https://forum.world.st/How-to-kill-an-overlapped-thread-tp3373253p3373258.html
maurel wrote:
> From Dolphin I am calling an external dll, I am using the overlap
> mechanism
> because the call returns in 10 mins.
>
> Is there a way to stop such a call while it is executing ? perhaps by
> killing
> the overlapped thread ?
I don't think it's ever a good idea to kill executing code (in any language)
without the co-operation of that code. E.g. if you kill a thread running code
in an external DLL then you could cause all kinds of damage to that code's
datastructures (trash the malloc arena, for instance).
But if you /do/ have the co-operation of the other code (e.g. you wrote it
yourself) then it becomes easy to set a "stop" flag that the code checks
periodically.
If not then I'd say that the only safe (in general) thing to do is to start a
new OS process to do the work (start a .exe). That should be safe to kill,
provided that it's been properly written. Alternatively, you could just let
the operation run to completion and ignore the result (simple, but not such a
great idea if the external function is compute-heavy or is doing a lot of I/O).
-- chris