Christopher Coale wrote:
> Asad Abbas wrote:
>>
>>
>> Why the Cpu Usage Boosts to 100% While running this simple Prog?
>>
>> can this code damage cpu?
>> How long will it take to damage a CPU?
>>
>> I know this contains a infinite loop, but this is simple prog in KB
>> and we run progs and games which are much much larger than this at
>> that cpu doesnt boosts to 100%
>> main()
>> {
>>
>> while (1)
>> {
>> }
>> getche();
>> return 0;
>> }
>
> For one, games and larger programs don't have empty-bodied loops (for
> the most part). And no, it won't damage the CPU any more than any other
> program will. The CPU is ALWAYS executing code, no matter what. It does
> not "pause" it's execution (even when you "sleep" your program). As for
> why the CPU usage goes up with an empty loop, is because it executes so
> quickly (resulting in more instructions being executed in the same time
> slice).
Actually, that isn't true. When you get a new computer, it is a pretty
good idea to run it through a CPU, RAM, and HD burn-in test. Those
software programs are designed to run everything at peak temperature for
24 hours. If they survive such tests, then they likely will survive
another 5-10 years easy.
I once ran a program that chugged 100% CPU, RAM, and most of a 20GB HD
for a good month. It was in the middle of January in the Midwest (it
was a miserable -20 Fahrenheit outside) and I had to have the windows
open and the heat turned off to keep the room temperature around 85
Fahrenheit. People were literally begging me to turn off the program.
That computer still works fine.
In another situation, I wrote a program similar to yours. Only I
changed the priority of the process to REALTIME_PRIORITY_CLASS before
the while loop by calling SetPriorityClass(). Upon running the program,
it instantly and completely froze Windows, forcing me to hit the reset
button on the box. There was no way to see what was going on, but the
program was surely spinning the CPU as fast as it could possibly go. No
damage done.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/