1

I used the NameThreadForDebugging in my application to name all my custom threads and even a main thread.

Now I see in Delphi IDE's Threads window seven threads. Three of them are my threads, but four other have no names and contain following call stacks:

Thread 1

ntdll.NtWaitForMultipleObjects
kernel32.BaseThreadInitThunk
ntdll.RtlInitializeExceptionChain
ntdll.RtlInitializeExceptionChain

Thread 2

ntdll.NtWaitForWorkViaWorkerFactory
kernel32.BaseThreadInitThunk
ntdll.RtlInitializeExceptionChain
ntdll.RtlInitializeExceptionChain

Thread 3

ntdll.NtWaitForMultipleObjects
kernel32.WaitForMultipleObjectsEx
C:\Windows\syswow64\USER32.dll
USER32.MsgWaitForMultipleObjects

etc.

They aren't TTimer objects because timers do not produce separate threads. What are they?

Paul
  • 25,812
  • 38
  • 124
  • 247
  • 2
    In general terms they are threads managed by "the system" for "system stuff". A similar question was asked for a different "mystery thread" [on Raymond Chen's blog](https://blogs.msdn.microsoft.com/oldnewthing/20140212-00/?p=1793). Generally you only need to focus attention on your threads and let Windows get on with doing its job in the background. See also [this Stack Overflow question and the various responses](http://stackoverflow.com/questions/34822072). – blong Mar 28 '17 at 15:09

1 Answers1

3

Those threads are associated with a threadpool, specifically the TpWorkerFactory object manager introduced with Windows Vista. NtWaitForWorkViaWorkerFactory (in thread #2) is part of the internal implementation of the threadpool and the other two threads are most likely worker threads which belong to the threadpool.

In the RTL these are almost certainly default objects created to implement the PPL functionality introduced in the System.Threading unit.

J...
  • 30,968
  • 6
  • 66
  • 143