[fpc-pascal] is it possible to kill a thread from within fpc?
jonas.maebe at elis.ugent.be
Thu Sep 25 18:02:22 CEST 2014
On 25/09/14 17:10, Dennis Poon wrote:
> I want to kill a thread created by my fpc program (not killing the
> entire process).
> I have to use an external win32 dll.
> I am already calling it from a separate thread but still, that dll
> something goes into an infinite loop which made my thread freezes.
> How do I kill this particular thread? Just by calling MyThread.terminate
> definitely just does not work.
> Is it even possible?
There is no FPC-supplied functionality for this. In general, killing
threads from an external thread is something you should never do,
because you have no idea what kind of resources this may leave dangling.
Terminating another thread at any point was available in early Java
versions, and was removed later. It was also available in old Delphi
versions and was removed later. Just don't do it.
Calling "terminate" sets the "terminated" property to "true", which you
can check in the run loop in the thread and make it exit itself at this
(presumably safe) point.
More information about the fpc-pascal