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. Problem with thread

Problem with thread

Scheduled Pinned Locked Moved C / C++ / MFC
help
2 Posts 2 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.
  • M Offline
    M Offline
    Majid Shahabfar
    wrote on last edited by
    #1

    Hi dear, I created a thread. But when I start the thread CPU load become 100%. I use these code. void CtestDlg::BeginThread() { m_isRunning = TRUE; AfxBeginThread(ThreadStart,this,THREAD_PRIORITY_LOWEST); } UINT CtestDlg::ThreadStart(LPVOID pParam) { CtestDlg* pDlg = (CtestDlg*)pParam; if (pDlg == NULL || !pDlg->IsKindOf(RUNTIME_CLASS(CtestDlg))) return 1; // if pEventLine is not valid while(pDlg->m_isRunning) pDlg->Start(); return 0; // thread completed successfully } void CtestDlg::Start() { } Start function doesn't have any code. Thank you in advance.

    M 1 Reply Last reply
    0
    • M Majid Shahabfar

      Hi dear, I created a thread. But when I start the thread CPU load become 100%. I use these code. void CtestDlg::BeginThread() { m_isRunning = TRUE; AfxBeginThread(ThreadStart,this,THREAD_PRIORITY_LOWEST); } UINT CtestDlg::ThreadStart(LPVOID pParam) { CtestDlg* pDlg = (CtestDlg*)pParam; if (pDlg == NULL || !pDlg->IsKindOf(RUNTIME_CLASS(CtestDlg))) return 1; // if pEventLine is not valid while(pDlg->m_isRunning) pDlg->Start(); return 0; // thread completed successfully } void CtestDlg::Start() { } Start function doesn't have any code. Thank you in advance.

      M Offline
      M Offline
      Magnus Westin
      wrote on last edited by
      #2

      your while loop will generate 100% cpu, since you dont have any kind of blocking code inte CtestDlg::Start. What the CPU is doing is calling Start all the time. Magnus

      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