[MLton] sleep vs. nanosleep

Henry Cejtin henry.cejtin@sbcglobal.net
Tue, 12 Jul 2005 10:40:52 -0500


I  looked  some  on  the  web  and did some tests, and the results are pretty
goofy.  It seems that the glibc version of  sleep()  returns  the  number  of
seconds  left  if  it  is  awoken  by  an interrupt, else 0.  Also, if even a
SIGSTOP/SIGCONT arrive (i.e., process suspended, resumed) or any  thing,  the
sleep()  returns.   This  certainly doesn't match what the basis library spec
says either OS.Process.sleep or Posix.Process.sleep should do.  (The case for
signals being caught is not discussed.  Either way it should be specified.)

Any way, the basis spec seems to require that the code loop.

I  tried this in SML/NJ 110.44.  They don't have any OS.Process.sleep.  Their
Posix.Process.sleep yields a Time.time, returning the amount of time left  in
the  case  of  any  signal.   Just  as  the  sleep() in glibc, in the case of
SIGSTOP/SIGCONT and the like, it returns immediately on restart.

I think that the loop should probably be  put  in  since  with  both  sleep's
returning  unit  it  doesn't  make  much  sense to return early.  Again, this
should be spelled out in MLton docs.