i want to sleep my program for 50ms using no api, and no more then 1%cpu on 766 intel p3
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.
only other lib im using us user32
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.
NaN
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.....
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.
You could Hook the Message loop....and stop "All" Windows operations for a given number cycles....
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.
Pseudocode:
Pseudocode:
millisecs_to_sleep = 1000;
ms = millisecs_to_sleep;
while( true )
{
tick = GetTickCount() + millisecs_to_sleep;
sleep( ms );
DoStuffHere();
adjust = GetTickCount() - tick;
ms = millisecs_to_sleep - adjust;
}