[fpc-pascal] Question: Is there a global callback, when a thread gets terminated?

Marc Santhoff M.Santhoff at web.de
Tue Feb 12 16:56:17 CET 2019


On Mon, 2019-02-11 at 10:21 +0000, Michael Schnell wrote:
> > Yes, but how do I get notified, when the thread is gone, and I can free
> > the
> > memory (of the object that was created)?
>
> Ah, now I finally see the problem :)
>
> The only idea that comes in my mind is creating yet another thread or a
> TTimer (by means of "QueueAsyncCall") to poll if the original Threads still
> living. This supposedly would involve OS calls for getting the thread ID and
> for checking same for validity. Ugly ! :( .

If the LazLogger user has to put debugln() statements in his code, me thinks
it would be an acceptable price to tell him:

"If you are using debugln() inside threads, let each thread register with the
logger before first usage."

So the user could do sth. like

  LazLoggerObj.RegisterThread(<thread handle or ID>);

in the construction code of his threads. So you know the threads using the
logger. Same could be done in the destruction code, using the
".DeregisterThread()" method.

So you now the threads and their lifetime inside the logger.


HTH anyhow,
Marc

--
Marc Santhoff <M.Santhoff at web.de>



More information about the fpc-pascal mailing list