Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#173] OS.Process.sleep only works with whole numbers

Date:
2017-01-12 21:39
Priority:
3
State:
Open
Submitted by:
Bug Submitter (webuser)
Assigned to:
John Reppy (jhr)
Machine Architecture:
None
Operating System:
MacOS X
Component:
Basis Library
Resolution:
Accepted As Bug
Severity:
Major
OS Version:
10.12.2
SML/NJ Version:
110.80
Keywords:
OS Process sleep real int
URL:
Transcript (of reproduction):
Standard ML of New Jersey v110.80 [built: Fri Aug 19 07:49:58 2016] - [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable] [autoloading done] val dt = TIME {usec=1750000} : Time.time [autoloading] [autoloading done] 1484257107.91 1484257108.92 1484257109.92 1484257110.92 1484257111.92 1484257112.92 1484257113.93 1484257114.93 ^C Interrupt -
Source (for reproduction):
val dt = Time.fromReal(1.6); while true do ( print (Real.toString(Time.toReal(Time.now())) ^ "\n"); OS.Process.sleep(dt) );
Summary:
OS.Process.sleep only works with whole numbers

Detailed description
val dt = Time.fromReal(1.5);
OS.Process.sleep(dt)
Is supposed to sleep for 1.5 seconds, whereas it only does so for 1.

In general, all real-valued times supplied to sleep are floored to the smaller integer.

Submitted via web form by Leonid Zlotnikov <zlotnleo@gmail.com>

Comments:

Message  ↓
Date: 2017-09-18 17:39
Sender: John Reppy

We've decided to fix this bug by changing the semantics of Posix.Process.sleep() to use the most precise version of sleep/usleep/nanosleep that is available. This change will require changing the runtime-system API for sleep (which currently expects an integer number of seconds as the argument to sleep).

Also, the Posix.Process.alarm() function should receive a similar treatment, since recent versions os Posix also have ualarm().

Date: 2017-01-12 22:00
Sender: John Reppy

OS.Process.sleep is just a wrapper around Posix.Process.sleep, which maps onto the sleep(3) function that only sleeps integral units of time. Since the POSIX standard now has functions like usleep and nano-sleep, we should probably be using those in the Posix.Process implementation.

I'm not sure what the story for Windows is.

Attached Files:

Changes

Field Old Value Date By
assigned_tonone2017-01-12 22:00jhr
detailsval dt = Time.fromReal(1.5); OS.Process.sleep(dt) Is supposed to sleep for 1.5 seconds, whereas it only does so for 1. In general, all real-valued times supplied to sleep are floored to the smaller integer. Submitted via web form by Leonid Zlotnikov <zlotnleo@gmail.com> 2017-01-12 22:00jhr
ResolutionNone2017-01-12 22:00jhr
Transcript (of reproduction)Standard ML of New Jersey v110.80 [built: Fri Aug 19 07:49:58 2016] - [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable] [autoloading done] val dt = TIME {usec=1750000} : Time.time [autoloading] [autoloading done] 1484257107.91 1484257108.92 1484257109.92 1484257110.92 1484257111.92 1484257112.92 1484257113.93 1484257114.93 ^C Interrupt - 2017-01-12 22:00jhr
Source (for reproduction)val dt = Time.fromReal(1.6); while true do ( print (Real.toString(Time.toReal(Time.now())) ^ "\n"); OS.Process.sleep(dt) );2017-01-12 22:00jhr