Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the other threads in a default VCL application, and can they be named by purpose?

If you create a basic VCL application and execute it, there are a few threads running. What are each of the threads for and can they be named to make it easier to debug multi-threaded applications?

I try to name all my child threads and it would be useful in debugging to have a clear idea of what each child thread is doing when viewing the Thread Status debug window. (And if one isn't named it would be a hint to track it down and get it named.)

like image 575
Darian Miller Avatar asked Feb 20 '12 17:02

Darian Miller


1 Answers

A plain vanilla 32 bit VCL app in XE2, running on 64 bit Windows 7 has 3 threads. The main thread and two extras. The two extra threads are created in TApplication.CreateHandle by a call to WTSRegisterSessionNotification. If you want to name them then you can enumerate the threads in the process and call NameThreadForDebugging.

In my experience, it's very hard to keep track of all the threads in your app. As soon as your app becomes moderately complex then there are liable to be plenty of threads coming and going. I personally view the ones that I have not named as being somebody else's responsibility!

like image 161
David Heffernan Avatar answered Nov 12 '22 19:11

David Heffernan