14

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.)

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Darian Miller
  • 7,808
  • 3
  • 43
  • 62

1 Answers1

15

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!

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 6
    However, when you don't name your own, they quickly get lost in the muck. So the other rule I suggest is the converse; If it's mine, I better name it or it will get lost in the muck. If the delphi debugger could even HINT at what the thread does, or even mention the Delphi unit name context where this thread first appeared, it would be a big help to me. – Warren P Feb 21 '12 at 13:20