Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 19 Nov 2007 21:31:20 -0500
See below...
On Tue, 20 Nov 2007 01:40:19 GMT, Geoff <geoff@xxxxxxxxxxxxxxx> wrote:
On Sun, 18 Nov 2007 19:55:21 -0500, Joseph M. Newcomer****
<newcomer@xxxxxxxxxxxx> wrote:
Note that to tell what is going on, you must look at the listing when compiled in Release
mode with optimizations on; nothing done in debug mode is worth anything in terms of
measuring code quality or program efficiency. For example, here's the code VS6 produces.
Note that it produces LARGER code because the body of the for-loop is replicated TWICE! So
the "while(TRUE)" form actually generates smaller code. Note that this form, in OPTIMIZED
VS6 code, does not do the test.
Nonsense. You stated the K&R compiler did the silly thing of testing
the constant in the loop. I showed you exactly that behavior in VC6
compiler.
Did you? In debug mode, nothing, repeat nothing, matters. Testing the constant remains
silly. ONLY release code matters for the discussion.
****
K&R C was a non-optimizing compiler. Comparing apples to****
apples, the VC6 compiler is no better than an ancient 35 year old C
compiler.
Then how is it that I am able to demonstrate that VS6 does NOT do the test in release
mode?
****
Now you want to make some kind of point about optimizing****
being the only way to judge code quality and program efficiency and by
implication, that while(1) is preferable to for(;;) because it
optimizes better. Let me be the first to declare BS on that point.
Funny, it looked to me in the generated code from the compiler that while(TRUE) actually
produced smaller code. Perhaps you can explain how the code executes to convince me that
two instances of the code are smaller than one?
****
There is and should be no difference between the two properly formed****
constructs.
I agree. What surprised me was that VS6 treats them differently.
****
A compiler that has to be tweaked or coerced into****
performing equally well for each of them is a very poor one indeed.
Where did I say that the compiler has to be tweaked or coerced?
****
You also managed to produce code that makes the compiler thrash in****
some way and it would appear to have duplicated a block of code, after
"optimizing" I might add, that didn't exist in your pre-optimized code
that you probably didn't even look at.
Actually, I did. But only optimized code is worthy of discussion for code quality
discussions.
****
****
I will re-state for the record that the choice between while(constant)
and for(;;) is purely a matter of style and the choice should be what
makes sense for clarity and maintenance and not what the compiler is
putting out in debug or release mode. If you like littering your code
with pragmas to suppress the warnings about while(constant) or
lowering the warning thresholds on your compiler so you don't have to
be nagged, be my guest.
while(constant) and if(constant) should NEVER be diagnosed as representing a problem. The
fact that they do means that the compiler is doing something it shouldn't be doing. I am
not "lowering" the warning threshold, I am disabling an erroneously-conceived feature.
****
****
As for the extra code or the "useless" warnings, I suggest you bring
those questions to the Visual Studio product teams and explain it to
them. Maybe they can have it performing to your satisfaction by the
time they release VS 2015.
I doubt that. They make mistakes like this all the time and then declare them the
standards. Besides, since I can disable them, and it makes sense to disable them, they
don't need to do anything. What we need is something better than the gross /W3 and /W4
differences and a way of getting all the enable/disable settings as part of a build
profile that is ideal for whatever my project is.
[Footnote: my Ph.D. is in optimizing compiler technology. I did research in optimizing
compilers for many years, depending on metrics, somewhere between 5 and 10 years, and
worked in developing compilers and optimziation technology for a company that built
commercial optimizing compilers. I used highly-optimizing compilers from 1969 through
1984, went through a dismal set of years using the kind of crap that Unix users thought
was state-of-the-art (it was obsolete in 1970), and finally got to use the Microsoft
optimizing compilers, which on the whole are truly fine compilers, which is why the
double-instance code surprised me.
Newcomer, Joseph M. "Machine-Independent Generation of Optimal Local Code", Ph.D.
dissertation, Carnegie Mellon University, 1975. My advisor was William Wulf, one of the
world's experts on compiler optimization technology.
The basic principles of compiler optimization were laid out by about a dozen people over
the period of 1955-1985 and as far as I can tell, reading the literature, there have been
no new breakthroughs since the mid-eighties.]
joe
****
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Why INFINITE loop in a thread occupy so much CPU time??
- From: lostlander
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M . Newcomer
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: David Wilkinson
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M . Newcomer
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Geoff
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M . Newcomer
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Geoff
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Joseph M . Newcomer
- Re: Why INFINITE loop in a thread occupy so much CPU time??
- From: Geoff
- Why INFINITE loop in a thread occupy so much CPU time??
- Prev by Date: Re: Steps in displaying a UTF-16 BMP value using TextOutW() ???
- Next by Date: Re: UTF-16 and TextOutW()
- Previous by thread: Re: Why INFINITE loop in a thread occupy so much CPU time??
- Next by thread: Re: Why INFINITE loop in a thread occupy so much CPU time??
- Index(es):
Relevant Pages
|