Mark McIntyre <markmcintyre@spamcop.net> writes:[color=blue]
> On Tue, 15 Jul 2003 23:45:06 +0100, in comp.lang.c , "Malcolm"
> <malcolm@55bank.freeserve.co.uk> wrote:[color=green]
> >"Keith Thompson" <kst@cts.com> wrote in message[color=darkred]
> >>
> >> > otherwise, if you don't call sleep (or the like), that task or
> >> > thread will idle needlessly and waste cpu cycles.
> >>
> >> On some systems.
> >>[/color]
> >What systems can detect busy idling? How do they deal with it?[/color]
>
> <OT> Most sensible ones, and they deal with it by switching the task
> out. After all if its just twiddling its thumbs for 30 secs, then its
> sensible to swap it to disk for that time less a bit.[/color]
<OT> How can a sensible system tell the difference between a program
"twiddling its thumbs" and doing actual work? If a program contains
something like the following:
for (i = 0; i < SOME_BIG_NUMBER; i ++) {
/* do nothing; this loop should take about 30 seconds */
}
or even
/* non-portably assume that time_t counts seconds */
thirty_seconds_from_now = time() + 30;
while (time() < thirty_seconds_from_now) {
/* do nothing */
}
I'm skeptical that a typical (or any) operating system will be able to
figure out what the program is trying to do and swap it out for 30
seconds. Replacing the /* do nothing */ with some computation makes
this even harder.
(In the first case, of course, the compiler is free to replace the
loop with a single assignment to i, unless i is volatile.)
Or do you mean something else by "busy idling"?
--
Keith Thompson (The_Other_Keith)
kst@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"