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

Martin Frb lazarus at mfriebe.de
Thu Feb 7 13:11:18 CET 2019


On 06/02/2019 11:32, Michael Schnell wrote:
>> Anything else?
> Maybe the other thread could set a callback event property provided by the TThread sibling with a function it defines, and the thread that is associated with the TThread sibling calls this property in it's OnTerminate handler.
>

There are no "siblings".

The use case here would be LazLogger. User code can call a function 
"Debugln" this calls a method on a global object.
The object provides storage for log-level (by name), and indentation, 
and others.

Indentation would be best per thread. So if user code in a thread calls 
"Debugln" a thread-instance of the logger (or a wrapper to it) should be 
created. But that must be destroyed at some time.
User code should not be expected to deal with this destruction.
The logger has no knowledge of the TThread object. User code decides, if 
and how it is subclassed, and if and how OnTerminate is used.

As for the question, why create an object, why not just "threadvar 
indent". User code can create (within the same thread) more than one 
instance of the logger.
This I something that can be used in testcase, where the testcase wants 
to have a logger, but does not want to mix with the log of the tested 
code (maybe capture that log).



More information about the fpc-pascal mailing list