Cross-platform elapsed-time helper for the Linux, macOS, and Windows modules.
runningTime, runningTimeInternal, and get
runningTime
(-- timer) Returns a borrowed view of the module's shared timer state. It does not construct an independent timer.runningTimeInternal
(-- timer) Exposes the shared state used by runningTime. Its storage has module lifetime. Do not move, destroy, or mutate the shared state while callers rely on it.- macOS: the public member is
getandtime0is private, with the same shared-state design. - Windows: the public members are
initandget.
get
(-- seconds) Reads elapsed seconds from the shared timer as an unknown Real64 value. It performs run-time clock access even when the caller has only known inputs; the result is a value, not a reference to stored seconds. Reading get does not reset the origin.- Linux:
CLOCK_BOOTTIMEis sampled during module initialization.getreturns the seconds difference plus1e-9times the nanoseconds difference from that origin. The value is elapsed time from initialization, not the clock's raw time since boot. Normal sequential reads are nondecreasing. - Linux: a
clock_gettimeresult of-1during initialization orgetprintsFATAL: clock_gettime failed, result=followed by the Cerrnonumber, then terminates with status2. This is not DEBUG-dependent. With call tracing disabled, the default output has a second newline after the diagnostic. - macOS:
CLOCK_MONOTONICis sampled at initialization andgetsubtracts thattimespecwith the same seconds/nanoseconds formula. The same explicitclock_gettimefailure message and exit path are used. - Windows: initialization calls
QueryPerformanceFrequencyandQueryPerformanceCounter.getuses aSpinlockto serialize counter reads and accumulates counter deltas multiplied by the reciprocal frequency. Query return codes are discarded; there is no query-failure check equivalent to Linux/macOS. The elapsed-time contract assumes successful queries and no explicit reinitialization or state modification. OrdinarySpinlockchecks still apply.
init
(--) Windows: queries the counter frequency, records the initial counter, and resets accumulated time to zero.- It is called once during module initialization.
- A later explicit call resets the shared origin; perform it only when no concurrent timer access is possible, since
initdoes not acquire the timer lock.
Windows fields
Examples
Linux runtime example
"String" use
"control" use
"linux/runningTime" use
"linux/sync/sync" use
{} Int32 {} [
t0: runningTime.get;
0.01r64 sleepFor
t1: runningTime.get;
t1 t0 > toString print
LF print
0
] "main" exportFunction
Expected Output
TRUE
macOS runtime example
"String" use
"control" use
"macos/runningTime" use
"macos/sync/sync" use
{} Int32 {} [
t0: runningTime.get;
0.01r64 sleepFor
t1: runningTime.get;
t1 t0 > toString print
LF print
0
] "main" exportFunction
Expected Output
TRUE
See also
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.
- linux/Process · macos/Process · windows/Process: Cross-platform process wrapper with explicit creation, waiting, and termination helpers.