Thomas Hruska wrote:
>
>
> 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/
> <http://www.CubicleSoft.com/MyTaskFocus/>
>
>
Um, what part isn't true? It almost looks like those examples defend my
point. First, I'm not exactly sure what you are saying isn't true
because you quoted my entire response. So, I'll go through everything.
The CPU is, in fact, ALWAYS executing code (when powered on), no matter
what. Hence why x86 has the "hlt" instruction. Once the computer is
powered on, the BIOS is going to load your boot sector, the CPU will
jump to it, then the IP/EIP register will continually increment. This
means that no matter what memory value the IP/EIP register points to,
the CPU will treat it as an instruction, "execute" it, then increment
IP/EIP again, and so on... so yes, the CPU will always execute
SOMETHING. This is the reason why on Windows the "System Idle" process
always seems to use so much CPU - the CPU has to execute something, so
when no other thread needs a time slice, this thread/process gets it.
Saying that running an empty-bodied loop will damage the CPU is silly.
An empty loop is in a sense 1 instruction (jmp <address of this jmp
instruction>). If you are saying processes running at "100% CPU" is
damaging, then that is silly as well. The CPU itself will always be
running at 100% (unless the "hlt" instruction is executed, in which case
the CPU simply "stops"). And in case you're wondering, the "hlt"
instruction can't be executed by normal programs, only the OS kernel.
Here is another example. Assuming there is no OS running an application
(the BIOS loaded it into real mode), the following program (assembled by
NASM) is executed by the CPU:
[org 0x7c00]
jmp $
That would result in the concept of "100% CPU usage", however, it is not
damaging to the CPU because the CPU will always execute something,
meaning, it will always be at 100% usage. If you get rid of the jmp
instruction, the CPU will still continue executing whatever is in memory
from where ever (0x7C00) the program was loaded, resulting in 100% CPU
usage.
So, I guess, this extra long essay can be shortened into a simple
phrase: CPU usage is just a concept. ;)
[Non-text portions of this message have been removed]