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. AfxBeginThread() ???????????

AfxBeginThread() ???????????

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 1 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
    Static x
    wrote on last edited by
    #1

    Hi everybody, i am using a simple thread in my program, when i launch the thread it works , but slows my machine, in the task manager the CPU usage is 100% until the thread is ended. I am using simple AfxBEginThread(..) function ,is there any other way to make thread work , without slowing down my PC??? With Best Regards m0n0

    D J L 3 Replies Last reply
    0
    • S Static x

      Hi everybody, i am using a simple thread in my program, when i launch the thread it works , but slows my machine, in the task manager the CPU usage is 100% until the thread is ended. I am using simple AfxBEginThread(..) function ,is there any other way to make thread work , without slowing down my PC??? With Best Regards m0n0

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

      The mere existence of a secondary thread will not cause the CPU usage to jump to 100%. You are doing something in this thread to cause that. Without seeing your code, it's impossible to say.


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      1 Reply Last reply
      0
      • S Static x

        Hi everybody, i am using a simple thread in my program, when i launch the thread it works , but slows my machine, in the task manager the CPU usage is 100% until the thread is ended. I am using simple AfxBEginThread(..) function ,is there any other way to make thread work , without slowing down my PC??? With Best Regards m0n0

        J Offline
        J Offline
        Joel Holdsworth
        wrote on last edited by
        #3

        Well... The AfxBeginThread function will simple create a thread to do work on the controller function you specify. So the CPU usage is down to what's in the function you write. If you write a function which crunches numbers in a loop or whatver, then your CPU usage will go to 100% while the function keeps crunching. However, if you only need to run a calculation intermittently try using Sleep(100), or CEvents to put the thread into suspended animation giving the rest of the threads time to do their jobs. What are you trying to do with your worker thread? Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]

        S 1 Reply Last reply
        0
        • J Joel Holdsworth

          Well... The AfxBeginThread function will simple create a thread to do work on the controller function you specify. So the CPU usage is down to what's in the function you write. If you write a function which crunches numbers in a loop or whatver, then your CPU usage will go to 100% while the function keeps crunching. However, if you only need to run a calculation intermittently try using Sleep(100), or CEvents to put the thread into suspended animation giving the rest of the threads time to do their jobs. What are you trying to do with your worker thread? Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]

          S Offline
          S Offline
          Static x
          wrote on last edited by
          #4

          "What are you trying to do with your worker thread?" Pretty Lot, i am testing huge numbers(100 or more digits ) on primality. Actually i am doing lots of operations there,probably this makes my cpu go 100% , anyway thanks for attention to all :) m0n0

          1 Reply Last reply
          0
          • S Static x

            Hi everybody, i am using a simple thread in my program, when i launch the thread it works , but slows my machine, in the task manager the CPU usage is 100% until the thread is ended. I am using simple AfxBEginThread(..) function ,is there any other way to make thread work , without slowing down my PC??? With Best Regards m0n0

            L Offline
            L Offline
            LighthouseJ
            wrote on last edited by
            #5

            Change your priority to THREAD_PRIORITY_IDLE instead of the default which is normal. That'll lower the thread priority so it won't take your system with it. The command would be:

            CWinThread * threadptr = AfxBeginThread(
            pfnThreadProc, // thread function
            pParam, // pointer to data to use
            THREAD_PRIORITY_IDLE, // the idle priority, was THREAD_PRIORITY_NORMAL
            0, // stack size, 0 means default size
            0, // create and run immediately, don't suspend on creation
            NULL // no security attributes
            );

            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