1. Welcome to the eXophase.com forums!

    It looks like you're enjoying our site but haven't created an account yet. Why not take a minute to register for your own free account now?

    By joining, you will have access to post topics, browse threads ad-free, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

C/C++ windows Sleep, and timers.

Discussion in 'Division by Zero' started by slicer4ever, Jul 4, 2011.

  1. slicer4ever

    slicer4ever Coding random shit

    Last played:
    GTA V on Xbox 360
    hello all, i'm working on an application for windows which implements a timer class that uses clock based timers, and calls Sleep at the end of the primary loop to utilize as little cpu as possible.

    the problem is that calling sleep produces bad results from my timer code, i've determined this is because the time that you pass to sleep is only the minimal time that the system has to wait before giving back control to my program, so it may be longer than 1 ms, and can produce varied results.

    so my problem lies in that i don't want to utilize 100% cpu when my program obviously doesn't take that long to execute, but using Sleep destroys the accuracy of my timers(i've implemented high performance counter's as well, but they suffer the same problem).

    is there any way i can relinquish control to the os, but not lose accuracy in my timers?

    edit: realized my solution, instead of reseting the amount of time elapsed to 0 when i detect the timer has finished, i instead subtract the timelength, so if the time ran is > than time length it compensates for that, so ignore my post, solution discovered.

Share This Page

Style eXophase Default