Pause¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Pause[n]
pauses for at least n seconds.
Notes
Pause is accurate only down to a granularity of at least $TimeUnit seconds. The time elapsed during the execution of Pause is counted in SessionTime and AbsoluteTiming, but not in TimeUsed or Timing.Examples (4)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (2)¶
Applications (2)¶
Pause returns Null; zero waits not at all
A rational (or any NumericQ) duration is accepted
Implementation notes¶
Algorithm. builtin_pause blocks for at least n seconds of wall-clock
time and returns Null. pause_seconds coerces the argument to a machine
double, accepting integers, reals, bignums, rationals, MPFR reals, and any
NumericQ symbolic form (Pi, Sqrt[2], …) via numericalize — so Pause[1/4]
and Pause[Pi] behave like Mathematica; a genuinely non-numeric argument leaves
Pause[x] unevaluated. The double is split into whole seconds and nanoseconds
and handed to nanosleep, re-armed with the reported remainder whenever it
returns early on a signal (EINTR), so the full duration is always observed.
n <= 0 (or non-finite) waits not at all, matching Pause[0].
CPU vs wall clock. nanosleep consumes no CPU, so the elapsed time is
counted by the wall clocks (AbsoluteTiming, SessionTime) but is invisible to
the CPU clocks (Timing, TimeUsed) — the two clock sources distinguish the
cases for free, with no special-casing. Accuracy is bounded by the OS timer
granularity ($TimeUnit-scale).
Data structures / limits. struct timespec and a scalar; returns
expr_new_symbol(SYM_Null). ATTR_PROTECTED. A blocking wall-clock wait, not a
numeric kernel — no packed/Compile[] surface.
Protected.- Sleeps on a wall-clock timer (
nanosleep) that consumes no CPU, so the elapsed time is counted byAbsoluteTimingandSessionTimebut not byTimingorTimeUsed.Timing[Pause[1]]reports ≈ 0;AbsoluteTiming[Pause[1]]reports ≈ 1. - Accurate down to a granularity of at least
$TimeUnitseconds. - The sleep resumes across signal interruptions, so the full duration is always
observed ("at least
nseconds"). nmay be any non-negative number: an integer, real, rational (Pause[1/4]), or aNumericQsymbolic form (Pause[Pi]). Zero or negativenreturns immediately. A non-numeric argument leavesPause[x]unevaluated.
Attributes: Protected.
References¶
See also: AbsoluteTiming, SessionTime, Timing, TimeUsed, $TimeUnit, NumericQ
- Source:
src/datetime.c - Specification:
docs/spec/builtins/time-and-date.md - Tests:
tests/test_datetime.c
Notes & additional examples¶
Notes¶
Pause[n] blocks for at least n seconds of wall-clock time, then returns
Null. The argument may be any non-negative number — integer, real, rational
(Pause[1/4]), or a NumericQ symbolic form (Pause[Pi]); zero or negative
returns immediately, and a non-numeric argument leaves Pause[x] unevaluated.
The wait is a nanosleep, which consumes no CPU. So the elapsed time is counted
by AbsoluteTiming and SessionTime but not by Timing or TimeUsed:
Timing[Pause[1]] reports about 0, while AbsoluteTiming[Pause[1]] reports
about 1. The sleep resumes across signal interruptions, so the full duration is
always observed. Accuracy is bounded by the timer granularity $TimeUnit.