Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Where Does the Extra Thread Come From?

Where Does the Extra Thread Come From?

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cliff Hatch
    wrote on last edited by
    #1

    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

    N R D 3 Replies Last reply
    0
    • C 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

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      what type of application did u create?

      nave

      C 1 Reply Last reply
      0
      • N Naveen

        what type of application did u create?

        nave

        C Offline
        C Offline
        Cliff Hatch
        wrote on last edited by
        #3

        .NET 2002, MFC Application, MDI.

        1 Reply Last reply
        0
        • C 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

          R Offline
          R Offline
          Roger Stoltz
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • R Roger Stoltz

            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

            C Offline
            C Offline
            Cliff Hatch
            wrote on last edited by
            #5

            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

            R 1 Reply Last reply
            0
            • C Cliff Hatch

              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

              R Offline
              R Offline
              Roger Stoltz
              wrote on last edited by
              #6

              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

              C 1 Reply Last reply
              0
              • C 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

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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

                C 1 Reply Last reply
                0
                • R Roger Stoltz

                  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

                  C Offline
                  C Offline
                  Cliff Hatch
                  wrote on last edited by
                  #8

                  Many 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

                  1 Reply Last reply
                  0
                  • D David Crow

                    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

                    C Offline
                    C Offline
                    Cliff Hatch
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups