06-27-2023 10:31 PM
I'm coding in Visual (2017) C, and the task seems simple enough.
I am using CmtReleaseThreadPoolFunctionID to close threads. I haven't been calling CmtWaitForThreadPoolFunctionCompletion beforehand since I'm usually only closing threads inside SignalCommThreadToStop, a function that was made to wait for the thread to exit its functions, (although I wasn't the one who wrote it).
However, even after CmtReleaseThreadPoolFunctionID I still see the thread in the thread list and Parallel Stacks. Perhaps it's just my inexperience with multithreaded apps and C, but shouldn't unloaded threads not show up anymore?
I looked up how to kill threads normally in C, and found the answer was pthread.h; however, pthread.h is not native to Windows, and I don't want to install something new at this stage in the project. (Not to mention it doesn't make sense that pthread.h would be the only way to close threads in C. How was pthread.h created without pthread.h?)
Finally, another person online (not working in Lab Windows) said that I shouldn't be closing threads at all and that I should put them in a loop. This doesn't make any sense at all to me, as once CmtReleaseThreadPoolFunctionID is called, the thread won't be used again, and as such any remnants of the thread are just wasting memory, and seemingly processing time; as even "dead" threads that appear to no longer be in use, will change location.
My program typically accumulates over 20 dead threads during startup, and I think it might be causing performance issues. How do I remove them from memory?
P.S. Almost all these threads are related to WiFi connectivity, and no I do not have time to rewrite the program to not use as many threads.
06-27-2023 10:47 PM
Here's a snapshot of my program's threads, from the thread viewer. The second flagged thread should have just been released.