On Tue, Jan 30, 2001 at 10:49:56AM -0500, Dan Sugalski wrote:
> At 09:43 AM 1/30/2001 -0600, Jarkko Hietaniemi wrote:
> >On Tue, Jan 30, 2001 at 04:13:39AM -0500, Michael G Schwern wrote:
> > > Is there any really good reason why sleep() doesn't work for
> > > microseconds?  I mean, if I can do this:
> > >
> > >     sub sleep {
> > >         my($time) = shift;
> > >         if( /^[+-]?\d+$/ ) {
> > >             sleep($time);
> > >         }
> > >         else {
> > >             select(undef, undef, undef, $time);
> > >         }
> > >     }

[return value not perfect for sleep when you call select]

> Also there isn't a portable way to do subsecond sleeps. Not that it's 
> stopped perl before, but on some of the platforms that perl 5 runs on there 
> isn't *any* way to do it.

You don't need to do it, do you?

man 3 sleep

RETURN VALUE
       Zero  if  the requested time has elapsed, or the number of
       seconds left to sleep.

man perlfunc

    sleep EXPR
       sleep   Causes the script to sleep for EXPR seconds, or
               forever if no EXPR.  May be interrupted if the
               process receives a signal such as "SIGALRM".
               Returns the number of seconds actually slept.  You
               probably cannot mix "alarm" and "sleep" calls,
               because "sleep" is often implemented using
               "alarm".


So on a system that can't do a subsecond sleep, you do the integer sleep
and return (aargh, C and perl differ) how long you slept for.

How does the program discover if sleep can do subseconds?
use Config; ?

Nicholas Clark

Reply via email to