Re: Why INFINITE loop in a thread occupy so much CPU time??



Joseph M. Newcomer wrote:
Perhaps because you asked it to? If you write a computation that consumes all the CPU, it
is going to, guess what, consume all the CPU! And that's what you've written! So
presumably you WANT to consume 100% of the available CPU time.

I have no idea what while(1) means anyway. while(TRUE) makes sense; while(true) makes
sense. What's an integer got to do with it?

Joe:

Well, while(1) and while(TRUE) are in fact the same thing. while(1) is often used in C where there is no bool type.

I agree that while(true) is preferred, but all these constructs produce warnings in recent VC versions at level 4 (at least in C++ mode), and the preferred usage is for(;;). I find this ugly, but have started using it since I started compiling at level 4.

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: Why INFINITE loop in a thread occupy so much CPU time??
    ... is going to, guess what, consume all the CPU! ... presumably you WANT to consume 100% of the available CPU time. ... I agree that whileis preferred, but all these constructs produce warnings in recent VC versions at level 4, and the preferred usage is for. ...
    (microsoft.public.vc.mfc)
  • Re: Where to find statistics for fetched programs?
    ... I got the question how frequently programmes are fetched, ... and then how much CPU they consume. ... This in order to put together kind of a hit parade of big CPU consumers & then tackle their tuning. ... RMF can't help me while Monitor I and Monitor III provide long-term data collection about system workload and resource utilization, while covering all hardware and software components of the system. ...
    (bit.listserv.ibm-main)
  • Where to find statistics for fetched programs?
    ... I got the question how frequently programmes are fetched, ... and then how much CPU they consume. ... This in order to put together kind of a hit parade of big CPU consumers & then tackle their tuning. ... RMF can't help me while Monitor I and Monitor III provide long-term data collection about system workload and resource utilization, while covering all hardware and software components of the system. ...
    (bit.listserv.ibm-main)
  • Re: CPU usage, memory and virtual memory
    ... some applications can consume close to 100% cpu ... usage and freeze up the machine. ... tells me it consumes 99% cpu and a lot of memory and virtual memory ...
    (microsoft.public.vc.mfc)
  • Re: Managed directsound problem under heavy CPU load
    ... Whenever you have badly behaved threads that consume 100% CPU there is going ... The correct way is to yield at least once ... frequency of the call you're probably better off calling Sleep() with a ...
    (microsoft.public.win32.programmer.directx.audio)