Are threadvar variables being freed like regular managed vars? I guess that is all you need.

02.02.2019 14:00, fpc-pascal-requ...@lists.freepascal.org пишет:
Send fpc-pascal mailing list submissions to
        fpc-pascal@lists.freepascal.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
or, via email, send a message with subject or body 'help' to
        fpc-pascal-requ...@lists.freepascal.org

You can reach the person managing the list at
        fpc-pascal-ow...@lists.freepascal.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of fpc-pascal digest..."


Today's Topics:

    1.  Question: Is there a global callback,   when a thread gets
       terminated? (Martin)


----------------------------------------------------------------------

Message: 1
Date: Fri, 1 Feb 2019 16:47:01 +0100
From: Martin <f...@mfriebe.de>
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
Subject: [fpc-pascal] Question: Is there a global callback,     when a
        thread gets terminated?
Message-ID: <568aa108-445c-f72b-6884-5ca7682df...@mfriebe.de>
Content-Type: text/plain; charset=utf-8; format=flowed

Lets say you have a unit, with code that can be called from threads.
- The code  does not own the thread object, so it can *not* use
TThread.OnTerminate (assuming it could get hold of the thread object).
- Yet the code wants to use "threadvar" and create objects (or otherwise
allocate mem). The code should return the memory, when the thread
terminates.
- The user of the code should not need to make any calls, to initiate
the clean up.

So that would need something like
    GetCurrentThreadObject.AddThreadTermationHandler(MyHandler);
or
    GlobalThreadTerminationHandler.Add(MyHandler);

MyHandler does not need the thread-id, or -object. But it needs to run
in the correct context for the ThreadVar. That is it needs to see the
value the threadvar has for the thread that is terminating.
So the Handler could do something like "myThreadVar.Free".

Any ideas?

I know the memory manager gets called "MemoryManager.DoneThread".
It is possible to intercept this, by getting the current mem-mgr,
replacing the method with a wrapper method (calling the original
method), and setting the mem-mgr.... Not particular nice.


------------------------------

Subject: Digest Footer

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

------------------------------

End of fpc-pascal Digest, Vol 176, Issue 2
******************************************

--
Best regards

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to