2017 001 Millisecond sleep

John Reppy edited this page May 3, 2017 · 1 revision

Proposal 2017-001

Millisecond sleep

Author: John Reppy
Last revised: May 3, 2017
Status: proposed
Discussion: issue #22


Synopsis

The original specification of OS.Process.sleep left the granularity of the sleep time unspecified (i.e., operating-system dependent). It was designed at a time when Unix provided the sleep system call with one-second granularity and it was expected that some implementations would just define OS.Process.sleep as an alias for Posix.Process.sleep.

This proposal would tighten the requirements on implementations of both OS.Process.sleep and Posix.Process.sleep to guarantee at least millisecond granularity (subject to the whims of operating system scheduling). It also makes the behavior of Posix.Process.sleep on negative time values consistent with OS.Process.sleep.

Description

The description of OS.Process.sleep should be replaced with the following:

  • sleep t suspends the calling process for the time specified by t. If t is zero or negative, then the calling process does not sleep, but returns immediately; i.e., exception is raised. The granularity of the sleep interval should be one millisecond or finer, although the actual time slept may be longer, owing to system latencies and possible limitations in the timer resolution of the hardware.

and the description of Posix.Process.sleep should be replaced with the following:

  • sleep t causes the current process to be suspended from execution until either t seconds have elapsed or until the recipt of a signal that is either caught or that terminates the process. If t is zero or negative, then the calling process does not sleep, but returns immediately; i.e., exception is raised. Dispite its name, this function should map to the POSIX nanosleep system call. The actual time slept may be longer than specified, owing to system latencies and possible limitations in the timer resolution of the hardware.

Rationale

Provides predictability across implementations without significant implementation cost. We use one millisecond as the required unit of granularity, since that is what the Windows Sleep function provides.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.