Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 186f1d605b53da58a2f434656c7c630b2d1b4d4a72823c3e1f7fa4e198b2503e
Ticket: b7b707a310ea42e9f1b29954ee8ca13ae91ccabe
[win32] NRT-only - NativeGetTime backwards time-drifts bug (fixed)
User & Date: sebres on 2026-09-14 00:12:57
Changes

  1. icomment:
    I wanted to add another new monotonic test case to clock.test (to cover in-sync-ticking with microseconds):
    <code><pre style="margin-left:15pt">
    test clock-33.13 {clock test, monotonic ticks in sync with microseconds (compiled only)} {
        lassign [::testClock::aligned-times microseconds monotonic] t1 t2
        set time [expr {$t1 - $t2}]; # microseconds alignment
        timerate {} 1; # short but precise busy wait
        lassign [::testClock::aligned-times microseconds monotonic] t1 t2
        if { $t2 + $time != $t1 } {
    	::tcltest::Skip "timing issue"; # did we experience time drift?
        }
    } {}
    </pre></code>
    
    But an attempt to test its stability failed on windows (I guess because of drifting through calibration):
    <code><pre style="margin-left:15pt">
    timerate {
        lassign [::testClock::aligned-times microseconds monotonic] t1 t2
        set time [expr {$t1 - $t2}]; # microseconds alignment
        timerate {} 1; # short but precise busy wait
        lassign [::testClock::aligned-times microseconds monotonic] t1 t2
        if { $t2 + $time - $t1 != 0 } {
    	::tcltest::Skip "timing issue ([expr {abs($t2 + $time - $t1)}] > 0)"; # did we experience time drift?
        }
    } 3000
    </pre></code>
    The microseconds sporadically drifting 1ms or 2ms compared to monotonic time.
    
    I cannot reproduce it in my fork with [fdfbd5e10] integrated (I also never saw microseconds drifts there).<br/>
    So I'll try to partially backport tclWinTime.c enhancement (inlined calibration for wall clock without calibration thread).
    
  2. login: "sebres"
  3. mimetype: "text/x-fossil-wiki"