How do I have my programs minimise CPU use when idle?
Say as an illustration that I’m writing a plan that sits from the background in Windows plus asks the consumer if they really want a walk once each 10 seconds.The naive way to achieve this in C++ i tried was basically to own a snippet of code roughly such as this:
while(haventQuit)
if(time PERCENTAGE 600 == 0)
sendMessage(“Do you choose some coffee”);
Now Windows, being polite, gives 13% of my cpu usage to the current program just making sure that it might blaze by means of that while loop a lot of times another, even nevertheless I in essence only want this system to just get up every moment or consequently to quickly find out if it ought of do anything after which you can resume sleep.
When will i tell Glass windows (from while in the program), basically, you don’t really need to give video games all all those cycles, just wake this up every now along with again
This will do
while(haventQuit)
if(time PERCENTAGE 600 == 0)
sendMessage(“Do you choose some coffee”);
sleep(60000); //Since 60000 ms = 1 minute;
Ones program can sleep with regard to 1 minute now, and there after it may again continue considering the while loop
However you possibly can specify time interval for which your system will slumber, and in that case continue.
In this way, your program will never consume extra CPU assets.
Thanks, Hope them helps
Sir, if oughout r lisenced users a windowed application u may use ‘SetTimer’ function which could execute the desired code following your given time period.
MY PARTNER AND I guess u know occurrence based progamming.
Leave a Reply
You must be logged in to post a comment.