I have a thread that sometimes freezes (I suspect) due to a DLL call that never returns. In the general case, where you have calls to blocking routines like Indy, is there a way of recovering from this in such a way that the thread OnTerminate handler fires? Will this happen if I call TerminateThread?
Asked
Active
Viewed 568 times
3
-
1Sounds more like good old fashioned deadlock, could easily be your threading code to blame – David Heffernan Oct 23 '11 at 07:27
1 Answers
9
TerminateThread()
is an immediate brute-force termination. It will NOT let the OnTerminaate
event fire. The only way OnTerminate
can fire is if the thread's Execute()
method exits through normal means, whether that be gracefully or by raising an uncaught exception (which will set the thread's FatalExpection
property).
In the case of Indy specifically, a blocking socket operation can be aborted by disconnecting the socket from the context of another thread. That is not usually possible with blocking DLL functions, unless they expose that kind of functionality in their API.

Remy Lebeau
- 555,201
- 31
- 458
- 770
-
Is that really ' **for** the context of another thread'? Or did you mean ' **from** the context of another thread'? If you did mean "for" is TIdContext involved and how would you go about doing it? – Marjan Venema Oct 23 '11 at 07:28