i want to sleep my program for 50ms using no api, and no more then 1%cpu on 766 intel p3
Posted on 2002-05-07 20:24:49 by Qages
When you sleep() all you're doing is reliquishing control to the operating system for x amount of time. There's no way to do it without communicating with Windows in some way.
Posted on 2002-05-07 22:45:27 by iblis
only other lib im using us user32
Posted on 2002-05-07 22:50:18 by Qages
Im not about to dig up the facts, cause its not that interesting to me, but my suggestion would be to use the floating point processor 80x87 doing some crazy stuff, which will leave the 80x86 free for other stuff, but stall the process till the FPU is finished.

Posted on 2002-05-07 23:12:47 by NaN
Why do it without the use of API? :confused: You have already linked to user32.dll, so obviously your app is not running before Windoze is fully loaded.....
Posted on 2002-05-08 07:42:43 by sluggy
I too am interested in a proper way to do this. The sleep API is not accurate enough for a lot of purposes and the windows system timer is also either inaccurate or in the case of multimedia timers to resource intensive.
Posted on 2002-05-08 07:56:38 by emonk
You could Hook the Message loop....and stop "All" Windows operations for a given number cycles....
Posted on 2002-05-08 08:28:25 by Brad
Unfortunately there's really no way to get "accurate" timings short of taking up 100% of the CPU resources. The best thing you can do is Sleep() for x amount of time and adjust for the innaccuracy.

millisecs_to_sleep = 1000;

ms = millisecs_to_sleep;

while( true )
tick = GetTickCount() + millisecs_to_sleep;
sleep( ms );


adjust = GetTickCount() - tick;
ms = millisecs_to_sleep - adjust;
Posted on 2002-05-08 11:53:26 by iblis