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. CPU usage 100%

CPU usage 100%

Scheduled Pinned Locked Moved C / C++ / MFC
hardwarequestion
4 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.
  • L Offline
    L Offline
    lynchspawn
    wrote on last edited by
    #1

    I have been using a simple routine to wait while connected hardware is performing a reset, ... The routine is: DWORD stop_time = GetTickCount() + iCount; while ((long)(GetTickCount() - stop_time) < 0L){ MSG msg; if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Someone has complained that the task manager in XP is showing that the CPU usage goes to 100% during this wait period. Do I need to add a sleep in there or something else to prevent this?

    A S M 3 Replies Last reply
    0
    • L lynchspawn

      I have been using a simple routine to wait while connected hardware is performing a reset, ... The routine is: DWORD stop_time = GetTickCount() + iCount; while ((long)(GetTickCount() - stop_time) < 0L){ MSG msg; if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Someone has complained that the task manager in XP is showing that the CPU usage goes to 100% during this wait period. Do I need to add a sleep in there or something else to prevent this?

      A Offline
      A Offline
      Andy Moore
      wrote on last edited by
      #2

      Yes. PeekMessage does not wait for a message to appear on the message queue before returning. Deus caritas est

      1 Reply Last reply
      0
      • L lynchspawn

        I have been using a simple routine to wait while connected hardware is performing a reset, ... The routine is: DWORD stop_time = GetTickCount() + iCount; while ((long)(GetTickCount() - stop_time) < 0L){ MSG msg; if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Someone has complained that the task manager in XP is showing that the CPU usage goes to 100% during this wait period. Do I need to add a sleep in there or something else to prevent this?

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Instead doing a busy wait try something like this: UINT_PTR tid = SetTimer(NULL, 1, 5000, NULL); MSG m; while (GetMessage(&m, NULL, 0, 0)) {      TranslateMessage(&m);      DispatchMessage(&m);        if ( m.message==WM_TIMER && m.wParam==1 )      {          break;      } } KillTimer(NULL, tid); Steve

        1 Reply Last reply
        0
        • L lynchspawn

          I have been using a simple routine to wait while connected hardware is performing a reset, ... The routine is: DWORD stop_time = GetTickCount() + iCount; while ((long)(GetTickCount() - stop_time) < 0L){ MSG msg; if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } Someone has complained that the task manager in XP is showing that the CPU usage goes to 100% during this wait period. Do I need to add a sleep in there or something else to prevent this?

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Check Raymond Chen's blog[^], he recently posted about waiting for messages while also having a timeout. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          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