Thread: Sleep hiccuping

  1. #1
    Registered User
    Join Date
    Aug 2004

    Sleep hiccuping

    I have a directx and I am doing a crube fps limiter using Sleep. Before I use Sleep I use timeBeginPeriod(1) to make Sleep prcise to about 1ms. Everything works fine and it limits nearly perfectly except for occasional hiccups.

    I am just wondering if anyone else experienced this problem or has any fixes.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    fix: don't use sleep...

    Just keep track of the elapsed time and only call the render function if the desired amount has passed.

    long diff = time() - oldTime;
    oldTime = time();
    if (diff > desiredTime) {

  3. #3
    Registered User
    Join Date
    Aug 2004
    Well the point of Sleep is to keep the cpu usage low. I know your all gonna say it doesn't matter but it does to me. And why not use Sleep when it produces virtualy exactly as I want, except for this weird hiccup, and if I fix this hiccup problem this method that I am using will be perfect (and accurate to 0.01 seconds with very low CPU usage).

  4. #4
    Captain - Lover of the C
    Join Date
    May 2005
    What do you mean by a hiccup? A temporary lack in accuracy? I've never had a problem with Sleep although I don't watch it too closely.
    Don't quote me on that... ...seriously

  5. #5
    Registered User
    Join Date
    Aug 2004
    Ok I have figured out that the hiccup has to do with timeBeginPeriod(1). If I don't use that than it goes away.

    By hiccup I mean a pause for 500ms or more. But without timeBeginPeriod(1) the method is still very accurate and with no hiccups. I havn't tested on any other windows besides xp though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [pthread] cancellable sleep in win32?
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-11-2007, 02:30 AM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 09:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM