Jump to content
  • Advertisement
Sign in to follow this  
Andrew Russell

Waiting for CPU availablity

This topic is 4740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know a quick and dirty way of checking if the CPU is sitting idle (the Idle process has X% of the CPU)? What I am trying to achieve is a way to prevent (or delay) scheduled tasks from running while the CPU is busy doing other things. I was thinking of a wrapper program that would wait until the CPU was available before running another command. OS is Windows. Cross-platform and multi-CPU support are not necessary. Thanks chaps.

Share this post


Link to post
Share on other sites
Advertisement
You can use windows API with the performance counter

Here's a quick demo /w source code

http://www.codeproject.com/system/cpuusage.asp



But doing so is giving yourself a bunch of trouble ... I must admit that using a low-priority thread is, I beleive, the best solution ...

Share this post


Link to post
Share on other sites
Quote:
Anyone know a quick and dirty way of checking if the CPU is sitting idle (the Idle process has X% of the CPU)?

Err, thats technically impossible. To check what the CPU is doing, you need, that's right... the CPU, which means it won't be idle. ;)

But yeah, as other people have said, run at low priority, and you get the effect you need.

Note, this varies from OS to OS. On Windows, low priority processes will only be run when no higher-priority processes are available.

On Linux, a low priority process would still get occasional timeslices, even if a higher priority process is available. Just not as often as the high priority one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!