LDC_global_crt_ctor for threads
Marcel
marcelpi97 at gmail.com
Thu Apr 2 22:16:45 UTC 2020
On Thursday, 2 April 2020 at 17:07:58 UTC, Calvin P wrote:
> On Thursday, 2 April 2020 at 15:28:43 UTC, Marcel wrote:
>> Hello!
>> Is there a way to call a cleanup function when a thread
>> terminates, like with LDC_global_crt_ctor? I can't use module
>> ctor/dtors since I'm using BetterC.
>
> a simple scope(exit) do_clear(); in the thread entry function
> will do the work.
>
> if you need put them in multi files, you need constructor a
> global list or array, init from LDC_global_crt_ctor. then
> call from thread entry function.
Oh, I didn't explain my situation properly: I'm writing a memory
allocation library and there's some thread local state that I
must take care of when the thread exits. Now, I can always do as
you said and ask the user to place calls to certain functions at
thread main, but I'd really prefer if that was done
automatically. Also, using global lists for thread state
management will likely lower performance for applications that
rapidly create and delete threads...
Is there no other way?
More information about the digitalmars-d-ldc
mailing list