Thread: Odd Sleep() Within Thread Behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by CommonTater View Post
    A better technique might be to use a timer with a callback to your code. These are not pinpoint accurate either (+ - about 2ms) but they're going to be more accurate than Sleep()ing.
    WM_TIMER msgs are THE lowest priority in the OS msg queue, after WM_PAINT.

    Getting a consistent resolution of +/- 2 msec is impossible, getting +/- 50 msec is hard in any system under load.

    Quote Originally Posted by CommonTater View Post
    There are also techniques using GetTickCount() --a 1 millisecond heartbeat-- that should get you within a millisecond. Something like if(! GetTickCount() % 20) might be just what you need...
    GetTickCount is a low performance timer using the system timer, which has a minimum resolution of ~10 msec (closer to 15 msec on the sytems I use).

    I found it very difficult to get sub to one millisec timers on MS OS's (except CE) without using a filter driver.

    QueryPerformanceCounter() is much better resolution, but may have issues on threads running on differing cores of a multi core CPU (and if not implemented on the system hardware will default to call GetTickCount()).
    Last edited by novacain; 02-13-2011 at 01:16 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. API Thread HEADACHE
    By WaterNut in forum Windows Programming
    Replies: 11
    Last Post: 01-16-2007, 10:10 AM
  2. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  3. multithreading question
    By ichijoji in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2005, 10:59 PM
  4. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 08:50 AM
  5. Thread programming behavior
    By Alextrons in forum Windows Programming
    Replies: 3
    Last Post: 10-31-2001, 07:30 AM