|
-
June 3rd, 2005, 12:43 PM
#1
Reduce program's CPU usage
I want to have a program running in the background that performs a lot of calculations. The problem is, this program takes up 99% of my CPU and makes all other programs run very slowly.
I want to be able to have this program performing its calculations in the background and still be able to use other programs meanwhile, without the calculating program significantly affecting the other programs' performance. I don't mind if this means that the calculating program will run slower.
Is there a way I can do this?
Old Unix programmers never die, they just mv to /dev/null
-
June 3rd, 2005, 01:54 PM
#2
Re: Reduce program's CPU usage
Describe the calculation done in the worker thread. One possible solution is sleep. Is there an infinite loop?
Kuphryn
-
June 3rd, 2005, 02:08 PM
#3
Re: Reduce program's CPU usage
Lower the priority of your programm... Under Windows, look up SetPriorityClass and SetThreadPriority functions in MSDN.
99% CPU usage itself isn't bad, if your process has idle priority and don't use too much memory, it wouldn't interfere other programms' performance.
"Programs must be written for people to read, and only incidentally for machines to execute."
-
June 4th, 2005, 09:55 AM
#4
Re: Reduce program's CPU usage
If your task is to run in the background, it is defined as:
1. A finite process
2. Does not have a completion time frame
Based on these two criteria, we can assume that speed of calculation is not important, because if your goal is a specific amount of CPU usage, you cannot aim for a specific effective speed of calculation.
There is no good way of reserving CPU percent time on Windows, but the above advice of setting your process or thread priority to a lower grade will at best make Windows execute your thread only when no higher priority threads are active (not sleeping, waiting for mutexes, semaphores etc..). This is a very effective work strategy for background processes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|