Thread: 100 cpu

  1. #1
    Mmm. Purple.
    Join Date
    May 2002

    100 cpu

    i've noticed that using peekmessage is just like using while(1) and totaly consumes the cpu, what's the best delay to put into the loop?
    I was thinking sleep(0); what do you guys think?

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    The standard non-busy message loop is:
        BOOL bRet;
        MSG msg;
        while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
            if (bRet == -1)
                // handle the error and possibly exit
    If you want a delay in a PeekMessage() loop, yes you can use Sleep(1)(not Sleep(0)*) to give up the rest of the thread time slice when you have done whatever you need to do.

    *Apparently, Sleep(0) will only yield to threads with the same or higher priorites, while Sleep(1) or above will yield to any thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. questions on multiple thread programming
    By lehe in forum C Programming
    Replies: 11
    Last Post: 03-27-2009, 07:44 AM
  3. Upgrading my old CPU (for another old one!)
    By foxman in forum Tech Board
    Replies: 16
    Last Post: 01-11-2008, 05:41 PM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. Unconvertable?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2002, 08:10 PM