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. Behaviour of CreateThread compared to AfxBeginThread

Behaviour of CreateThread compared to AfxBeginThread

Scheduled Pinned Locked Moved C / C++ / MFC
c++
6 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.
  • S Offline
    S Offline
    sunny_vc
    wrote on last edited by
    #1

    Hi all, Im working in vc6.0 using MFC. When I create thread using AfxBeginThread(), if the thread is running then the CPU utilization shown is around 50%, even though the thread is doing nothing. It is called as: AfxBeginThread(PortReadThread,gpSerialPortCtrl,THREAD_PRIORITY_NORMAL); If I create the same thread using CreateThread(),even the thread is running the CPU utilization is around 0% It is called as: CreateThread( NULL,0,(LPTHREAD_START_ROUTINE) PortReadThread,(LPVOID) this,0,NULL); Is this the expected behaviour.If not please tell me why its behaving like that. Thanks in advance.

    Regards, Sunil Kumar

    N 1 Reply Last reply
    0
    • S sunny_vc

      Hi all, Im working in vc6.0 using MFC. When I create thread using AfxBeginThread(), if the thread is running then the CPU utilization shown is around 50%, even though the thread is doing nothing. It is called as: AfxBeginThread(PortReadThread,gpSerialPortCtrl,THREAD_PRIORITY_NORMAL); If I create the same thread using CreateThread(),even the thread is running the CPU utilization is around 0% It is called as: CreateThread( NULL,0,(LPTHREAD_START_ROUTINE) PortReadThread,(LPVOID) this,0,NULL); Is this the expected behaviour.If not please tell me why its behaving like that. Thanks in advance.

      Regards, Sunil Kumar

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

      Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().

      sunilkumar.d wrote:

      even though the thread is doing nothing.

      Nothing means? is it in some wait state?

      nave [OpenedFileFinder] [My Blog]

      S R 2 Replies Last reply
      0
      • N Naveen

        Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().

        sunilkumar.d wrote:

        even though the thread is doing nothing.

        Nothing means? is it in some wait state?

        nave [OpenedFileFinder] [My Blog]

        S Offline
        S Offline
        sunny_vc
        wrote on last edited by
        #3

        Not in wait state exactly.just to test the application i have put a while loop with empty braces in the thread.

        Regards, Sunil Kumar

        S N 2 Replies Last reply
        0
        • S sunny_vc

          Not in wait state exactly.just to test the application i have put a while loop with empty braces in the thread.

          Regards, Sunil Kumar

          S Offline
          S Offline
          Saurabh Garg
          wrote on last edited by
          #4

          Well thread is not doing nothing. The thread is busy executing infinite loop!!! -Saurabh

          1 Reply Last reply
          0
          • S sunny_vc

            Not in wait state exactly.just to test the application i have put a while loop with empty braces in the thread.

            Regards, Sunil Kumar

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

            sunilkumar.d wrote:

            Not in wait state exactly.just to test the application i have put a while loop

            Ho :doh: . Then the thread will definitly use cpu and the AfBeginThread() is working properly. I guess there is something wrong in calling Createthread() not in AfBeginThread(). :cool:

            nave [OpenedFileFinder] [My Blog]

            1 Reply Last reply
            0
            • N Naveen

              Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread. so basically there should not be any difference in CPU utitlization. Some additional tasks AfxBeginThread() perform is the initialization of MFC and CRT global variables and thread specific variables. Also try the _beginthread().

              sunilkumar.d wrote:

              even though the thread is doing nothing.

              Nothing means? is it in some wait state?

              nave [OpenedFileFinder] [My Blog]

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              Naveen wrote:

              Actually the AfxBeginThread() also calls the CreateThread() function internally to create a thread.

              Nope, that's wrong. AfxBeginThread calls _beginthreadex internally.

              There are some really weird people on this planet - MIM.

              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