[m-rev.] for review: bootstrap with MSVC as C compiler.
Peter Moulder
pmoulder at csse.monash.edu.au
Thu Nov 7 23:40:59 AEDT 2002
> [code for sleep or Sleep]
> +#else
> + /*
> + ** busy-wait for a few billion cycles, which should hopefully
> + ** take a second or more.
> + */
> + volatile int i;
> + for (i = 0; i < 100000000; i++)
> + {}
> #endif
I'm inclined to think that #error (or at least #warning, though my
inclination is for #error) is the right thing here. By all means
leave some example code someone can use as a last resort.
Rationale for drawing attention: The context of this code is waiting
for a forked vim process to have started. If fork exists but sleep
doesn't (according to configure) then there's a good chance that it's
just an error with the makefiles or configuration process, which the
user would probably want to fix.
Given that we're waiting for a process, we'd like to call yield() inside
our busy loop, though of course it might not be called yield on the
given platform. (I think a line like
yield(); /* I.e. hint to the operating system's scheduler that
it should give the CPU to some other process.
You may need to change `yield' to something else
for your platform though. */
should be added to the example code, in fact.)
Given that CPU speeds vary by many orders of magnitude (even before
considering how often context switching does in fact occur), it would
be nice to call time() inside the loop instead of counting to a billion.
(A comment might suggest clock() as a more portable but otherwise less
desirable alternative to time().) */
Suggested alternative code:
Check for time.h header file in configure.in.
#if !defined(HAVE_SLEEP) && !defined(HAVE_CAPITAL_S_SLEEP)
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#endif
...
#else /* neither sleep nor Sleep available */
#error "Neither sleep nor Sleep available. Please check \
your configuration or edit the code here. \
(An example replacement is provided.)"
{
time_t start = time(NULL);
/* If your platform doesn't have a time function,
you might try clock_t ... clock() / CLOCKS_PER_SEC. */
do {
yield();
/* I.e. hint to the operating system's scheduler that
it should give the CPU to some other process. You
may need to change `yield' to something else for
your platform though. */
} while((unsigned) (time(NULL) - start) <= 1);
}
#endif
(I'm half inclined not to bother providing the example code at all,
but it's written now.)
pjm.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list