www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Windows thread pool

reply Python <python python.com> writes:
If I am using the integrated Windows Thread Pool (1), how this 
will interact with garbage collection? Is there any risk that 
some objects are never freed or some are freed too soon? Can the 
garbage collector stop the threads as needed?

I am asking that because I cannot use the managed 
core.thread.Thread having gc support, nor I can use attachThis() 
since the nature of the Win thread pool is dynamic, threads are 
created dynamically by OS depending on several factors, I have 
access only to the callbacks run on these threads.

(1) 
https://learn.microsoft.com/en-us/windows/win32/procthread/thread-pool-api

Thanks.
May 19
parent evilrat <evilrat666 gmail.com> writes:
On Monday, 19 May 2025 at 16:01:12 UTC, Python wrote:
 If I am using the integrated Windows Thread Pool (1), how this 
 will interact with garbage collection?
It won't even know this threads exists, this also means that your next question:
 Is there any risk that some objects are never freed or some are 
 freed too soon?
Because the GC is unaware of these threads any objects will be early freed. What you can do however, since you know the program logic and flow - when the objects allowed to created and destroyed, then by using GC.addRoot/GC.removeRoot keep them alive and release when no longer needed.
Can the garbage collector stop the threads as needed?
No.
May 20