Where Does the Extra Thread Come From?
-
I'm working on an application that launches a separate thread for some processor intensive activities. I used Spy to look at the running application, expecting to see two threads - but there were three! I can make out the main thread and the one that I launched. Both these clock up CPU time as expected. The third thread doesn't appear to do anything - CPU time etc. stays at zero. The application works fine - I'm just curious to know where the extra thread comes from. I assume the system creates it automatically for some purpose. Does anyone know what it might be for? Best Regards Cliff Hatch
-
I'm working on an application that launches a separate thread for some processor intensive activities. I used Spy to look at the running application, expecting to see two threads - but there were three! I can make out the main thread and the one that I launched. Both these clock up CPU time as expected. The third thread doesn't appear to do anything - CPU time etc. stays at zero. The application works fine - I'm just curious to know where the extra thread comes from. I assume the system creates it automatically for some purpose. Does anyone know what it might be for? Best Regards Cliff Hatch
-
.NET 2002, MFC Application, MDI.
-
I'm working on an application that launches a separate thread for some processor intensive activities. I used Spy to look at the running application, expecting to see two threads - but there were three! I can make out the main thread and the one that I launched. Both these clock up CPU time as expected. The third thread doesn't appear to do anything - CPU time etc. stays at zero. The application works fine - I'm just curious to know where the extra thread comes from. I assume the system creates it automatically for some purpose. Does anyone know what it might be for? Best Regards Cliff Hatch
Debug your application and halt it after your second thread is created and it has ran for a while. Switch the context of the unknown thread and have a look at the bottom of the call stack. Does it say something with 'RPC'?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998
"...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above -
Debug your application and halt it after your second thread is created and it has ran for a while. Switch the context of the unknown thread and have a look at the bottom of the call stack. Does it say something with 'RPC'?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998
"...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying aboveThanks for the suggestion Roger, but I'm having difficulty following your instructions. All the threads close down cleanly when I halt - I assume you mean "pause"? How should I switch the context of the unknown thread? The number of switches increments when I refresh the Spy properties window - is this what you mean? I don't see how the call stack or anything else will be affected when the application is paused. Apologies for this - I think I must be completely mis-interpreting your suggestion - could you provide some clarification? Best Regards Cliff
-
Thanks for the suggestion Roger, but I'm having difficulty following your instructions. All the threads close down cleanly when I halt - I assume you mean "pause"? How should I switch the context of the unknown thread? The number of switches increments when I refresh the Spy properties window - is this what you mean? I don't see how the call stack or anything else will be affected when the application is paused. Apologies for this - I think I must be completely mis-interpreting your suggestion - could you provide some clarification? Best Regards Cliff
Cliff Hatch wrote:
All the threads close down cleanly when I halt - I assume you mean "pause"?
:-> Ummm, terminology stuff... Yes, I meant "pause", otherwise the rest of my suggestions would not be of any use. :) Find the menu option 'Threads...', in VC6 it's under the 'Debug' menu. Inside the small thread window you can choose which thread you'd like to see the context for. As I understood it there will be three whereas you'll recognize the top of the call stack for two of them since it most likely will be your own code. The third is the unknown and it would help a lot if you can provide information about the call stack for that thread.
Cliff Hatch wrote:
I don't see how the call stack or anything else will be affected when the application is paused.
Of course the call stack won't change during the application pause, but the contents of the call stack are important: what's at the bottom and what's at the top of the call stack.
Cliff Hatch wrote:
Apologies for this - I think I must be completely mis-interpreting your suggestion
No worries! -- Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998
"...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above -
I'm working on an application that launches a separate thread for some processor intensive activities. I used Spy to look at the running application, expecting to see two threads - but there were three! I can make out the main thread and the one that I launched. Both these clock up CPU time as expected. The third thread doesn't appear to do anything - CPU time etc. stays at zero. The application works fine - I'm just curious to know where the extra thread comes from. I assume the system creates it automatically for some purpose. Does anyone know what it might be for? Best Regards Cliff Hatch
The other thread could come from code other than yours. For example, use Task Manager to watch Visual Studio's thread count. Now open a file, and watch the thread count increase by several.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Cliff Hatch wrote:
All the threads close down cleanly when I halt - I assume you mean "pause"?
:-> Ummm, terminology stuff... Yes, I meant "pause", otherwise the rest of my suggestions would not be of any use. :) Find the menu option 'Threads...', in VC6 it's under the 'Debug' menu. Inside the small thread window you can choose which thread you'd like to see the context for. As I understood it there will be three whereas you'll recognize the top of the call stack for two of them since it most likely will be your own code. The third is the unknown and it would help a lot if you can provide information about the call stack for that thread.
Cliff Hatch wrote:
I don't see how the call stack or anything else will be affected when the application is paused.
Of course the call stack won't change during the application pause, but the contents of the call stack are important: what's at the bottom and what's at the top of the call stack.
Cliff Hatch wrote:
Apologies for this - I think I must be completely mis-interpreting your suggestion
No worries! -- Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998
"...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying aboveMany thanks for this Roger. I didn't know the "Threads" window existed. I found it under "Debug", "Windows", "Threads" in .NET 2002, and suddenly your original post makes perfect sense. :) The unknown thread has the generic sounding title "Win32 Thread", and the call stack contains just two entries: ntdll.dll!7c90eb94() kernel32.dll!7c80b683() I'm still curious about what it does, but it is clearly a system thing (see also reply from David Crow below). I'm happy to accept that - and even happier to have discovered a new Visual Studio feature along the way. :-D Best Regards Cliff -- modified at 12:11 Tuesday 5th December, 2006
-
The other thread could come from code other than yours. For example, use Task Manager to watch Visual Studio's thread count. Now open a file, and watch the thread count increase by several.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Thanks David Yes, I see the thread count changing. There seem to be a number of short-lived threads in addition to the persistent one I noticed. Best Regards Cliff