Skip to content
Tcl Source Code History Of Ticket 3328635
Login

History Of Ticket 3328635

Artifacts Associated With Ticket 3328635

  1. Ticket change [a36f783de6] (rid 110045) by ferrieux on 2011-06-24 20:37:32:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      In threaded unix builds, timer events use pthread_cond_timedwait, which needs an absolute target time. The computation of this target is broken, because it adds the (correct) scaled==real delta to the (incorrect) virtual Tcl_GetTime. The fix is to use real time for the latter.
      
      Moreover, in some unices, the clock used for pthread_cond_timedwait can be selected among several, with pthread_condattr_setclock at condvar creation time. One of them, CLOCK_MONOTONIC, has the extra advantage of being insensitive to system clock tweaks. I think that selecting it when possible can only improve things, since it allows:
      
           - usual, tip-302-sensitive [after] semantics unchanged, since the timer events are also stored as absolute epoch-time  targets by Tcl
           - fully working Virtual Time with clock_gettime(CLOCK_MONOTONIC) giving tip-302-insensitive [after].
      
      I have a provisional patch for platforms with clock_gettime+CLOCK_MONOTONIC, designed to enable Joe Keen's code in http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/8f820c68143850f9# . Some autogoo would be due before committing.
      
      An alternative to 'select monotonic if possible, epoch if not' would be a runtime setting, like a ::tcl::unsupported::monotonicTime linked var. To be discussed.
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "7 High"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "ferrieux"
    10. subsystem initialized to: "03. Timer Events"
    11. title initialized to: "Virtual Time broken on threaded unix"
    12. type initialized to: "Bug"
  2. Add attachment "tim.patch" [1e38fbdf69] (rid 90937) by ferrieux on 2011-06-25 03:41:02.

  3. Ticket change [8b419916b3] (rid 127530) by ferrieux on 2011-06-25 03:41:03:

    1. icomment:
      
      
      File Added - 415876: tim.patch
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  4. Ticket change [8831e44fed] (rid 131829) by ferrieux on 2011-06-25 03:50:44:

    1. icomment:
      Actually, if we choose the explicit selection approach, the toggle should rather be accessible at C level, by the extensions able to benefit from it: Tcl_SetClockKind( 0==normal, 1==monotonic). This way, an extension can enable the tweak-unsensitive [after] in a completely self-contained way. If you like this method I'll write the patch shortly.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  5. Ticket change [d830b8c41a] (rid 107396) by ferrieux on 2011-07-23 00:59:02:

    1. icomment:
      Pasting Roy Keene's kind crash-course on autoconf:
      
      [19:49]<rkeene>AC_DEFUN(TCL_CHECK_CLOCK_BLAH, [ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[contents-outside-of-main]], [[contents-of-main]]), [ AC_DEFINE(HAVE_CLOCK_GETTIME, [1], [Define to 1 if you have whatever clockgettime is]) ]) ])
      
      Then, as Roy suggests, do the runtime part (is CLOCK_MONOTONIC working here ?) at Tcl init time.
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  6. Ticket change [00f8f9c94d] (rid 119400) by jenglish on 2011-07-23 01:35:28:

    1. icomment:
      You don't need autogoo to detect this, POSIX specifies preprocessor macros you can test instead.  
      
      See <URL: http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html >, or `man 7 posixoptions ` on a glibc system, for details.  But basically: #if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK).  Come to think of it, you could just use #if defined(CLOCK_MONOTONIC) ...
      
      
      
      
    2. login: "jenglish"
    3. mimetype: "text/plain"
    4. username: "jenglish"
  7. Ticket change [45a3397792] (rid 99383) by jenglish on 2011-07-23 01:51:58:

    1. icomment:
      Also - as a falllback, if _POSIX_MONOTONIC_CLOCK / CLOCK_MONOTONIC is not available, a suitable fallback is CLOCK_REALTIME; this is guaranteed present if _POSIX_TIMERS are available at all, will be no more broken than gettimeofday() (which is what's currently used), and  less broken than the damaged TIP#233 version.
      
      Re:  option to enable/disable this from Tcl scripts or C code -- ISTM this would be an "Old buggy behaviour [Y/N]?" type question, I don't see any reason to preemptively offer this as an option.
      
      
    2. login: "jenglish"
    3. mimetype: "text/plain"
    4. username: "jenglish"
  8. Ticket change [73e22eac79] (rid 105111) by ferrieux on 2011-07-24 21:38:18:

    1. icomment:
      Thanks for the POSIX macros: simpler indeed !
      For the "#if defined(CLOCK_MONOTONIC)", are we sure that when it's here it's always a macro, not a direct enum ?
      Last, is there a typo in your last sentence ? Shouldn't it read "I don't see any reason *not* to preemptively offer this as an option" ?
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  9. Ticket change [667ebd0d64] (rid 140201) by dgp on 2014-10-09 14:33:10:

    1. assignee changed to: "aku"
    2. closer changed to: "nobody"
    3. comment changed to:
      In threaded unix builds, timer events use pthread_cond_timedwait, which needs an absolute target time. The computation of this target is broken, because it adds the (correct) scaled==real delta to the (incorrect) virtual Tcl_GetTime. The fix is to use real time for the latter.
      
      Moreover, in some unices, the clock used for pthread_cond_timedwait can be selected among several, with pthread_condattr_setclock at condvar creation time. One of them, CLOCK_MONOTONIC, has the extra advantage of being insensitive to system clock tweaks. I think that selecting it when possible can only improve things, since it allows:
      
           - usual, tip-302-sensitive [after] semantics unchanged, since the timer events are also stored as absolute epoch-time  targets by Tcl
           - fully working Virtual Time with clock_gettime(CLOCK_MONOTONIC) giving tip-302-insensitive [after].
      
      I have a provisional patch for platforms with clock_gettime+CLOCK_MONOTONIC, designed to enable Joe Keen's code in http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/8f820c68143850f9# . Some autogoo would be due before committing.
      
      An alternative to 'select monotonic if possible, epoch if not' would be a runtime setting, like a ::tcl::unsupported::monotonicTime linked var. To be discussed.
      
    4. icomment: "status?"
    5. login: "dgp"
    6. mimetype: "text/plain"
    7. severity changed to: "Minor"
  10. Ticket change [6069f0f4e3] (rid 140202) by dgp on 2014-10-09 14:33:28:

    1. icomment: "status?"
    2. login: "dgp"
    3. mimetype: "text/plain"
  11. Ticket change [fa798e0240] (rid 140219) by aku on 2014-10-09 17:33:46:

    1. icomment:
      A -nocase grep of the Tcl 8.6 sources does not show any use of 'monotonic' except tclCompile.h where it talks about source offsets put into the byte code.
      
      Ditto for Tcl 8.5.
      
      It seems that the patch is not applied.
      Bumping prio for self.
      
    2. login: "aku"
    3. mimetype: "text/plain"
    4. priority changed to: "9 Immediate"
  12. Ticket change [35b6e79c45] (rid 140221) by aku on 2014-10-09 18:24:11:

    1. icomment:
      The patch was not updated with the discussion about how to configure this.
      
      In the works now.
      
      Working on the Tcl 8.5 branch.
      
      Commit will be on a branch at first, for review (by Joe, who will become a contact here).
      
    2. login: "aku"
    3. mimetype: "text/plain"
  13. Ticket change [24f00ba79c] (rid 140222) by aku on 2014-10-09 18:52:43:

    1. icomment:
      The updated patch is now committed to branch "tkt3328635-posix-monotonic-clock".
      
      Pushed revision [265e84eb5e].
      I am asking for a general review by Joe and Alexandre.
      
      This code does not work yet! (on linux even).
      
      It compiles on my build system (RedHat FC4 Stentz), yet fails to link.
      It claims that clock_gettime() is missing (*).
      
      Checking with temporarily added #error lines showed that the code believes that both _POSIX_TIMERS and _POSIX_MONOTONIC_CLOCK are defined. From what I read in the discussion here and referenced web site and manpage that should mean that clock_gettime() is available. And it is ipmlied to be in the (g)libc.
      
      The glibc here is 2.3(.6).
      Should some other library be linked too ?
      
      Or could be a macro and I need a header which contains the proper mapping to the actual function name ?
      
      Further note that I tried to extend the patch to fall back to CLOCK_REALTIME where possible. Please review this part too.
      
      (Ad *): .../build/tcl-8.5/libtcl8.5.so: undefined reference to `clock_gettime'
      
    2. login: "aku"
    3. mimetype: "text/x-fossil-wiki"
  14. Ticket change [8d38f3fbfd] (rid 140229) by ferrieux on 2014-10-09 19:35:37:

    1. icomment:
      Will test and review asap; in the meantime, regarding the clock_gettime() missing symbol on glibc, my wheezy manpage says:
      
             Link with -lrt (only for glibc versions before 2.17).
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
  15. Ticket change [66b5e40e04] (rid 140231) by aku on 2014-10-09 19:58:08:

    1. icomment:
      Thanks. So this means we do need configure.in/tcl.m4 changes to know of the need for linking against librt, and when.
      
      Have to test on other platforms as well.
      
    2. login: "aku"
    3. mimetype: "text/plain"
  16. Ticket change [e1798a78e3] (rid 141695) by dgp on 2015-05-01 14:04:48:

    1. icomment: "status?"
    2. login: "dgp"
    3. mimetype: "text/plain"
  17. Add attachment "tip302.patch" [730ab53d42] (rid 145959) by chw on 2016-03-25 08:05:54.

  18. Ticket change [41fd882a69] (rid 148858) by chw on 2016-09-24 17:52:53:

    1. icomment:
      Not sure if this is the right ticket, but my patch to make things more
      insensitive against wall clock time changes is somewhat improved now,
      see attachment.
      
    2. login: "chw"
    3. mimetype: "text/plain"
  19. Add attachment "tip302.diff" [ed0ff1ba82] (rid 148859) by chw on 2016-09-24 17:53:13.

  20. Ticket change [76084bf6c7] (rid 148863) by chw on 2016-09-25 18:59:38:

    1. icomment:
      Latest version which is smaller and works hopefully on olden Windows < Vista, and is integrated into AndroWish now, can be found in attachment atip302.diff, please review.
      
    2. login: "chw"
    3. mimetype: "text/plain"
  21. Add attachment "atip302.diff" [3c2fbec300] (rid 148864) by chw on 2016-09-25 18:59:51.

  22. Ticket change [167791c18d] (rid 148880) by jan.nijtmans on 2016-09-26 09:40:47:

    1. icomment:
      Latest patch from Christian committed to branch "tkt3328635-posix-monotonic-clock". Applied to trunk in stead of core-8-6-branch, most likely this change is too intrusive for a patch release.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  23. Add attachment "atip302-85.diff" [10d700bd14] (rid 148916) by chw on 2016-09-28 10:31:16.

  24. Ticket change [62ab1a2355] (rid 151863) by chw on 2017-02-10 21:15:37:

    1. icomment:
      Sooorry, but couldn't resist.
      
      tcl is not dead yet ... https://www.youtube.com/watch?v=oZ2QiyxRiYs&feature=youtu.be&a -- jima, tclers chat, 2017
      
      Time is heavy sometimes; imagine how heavy eternity must be. -- E.M.Cioran, The Book of Delusions, 1936
      
    2. login: "chw"
    3. mimetype: "text/plain"
  25. Ticket change [3b8390574d] (rid 153084) by chw on 2017-04-13 00:23:12:

    1. icomment:
      From the Tcl'ers Chat for the record (citing myself, sorry):
      
      Regarding TIP#302: I don't remember any man page version of after(n) and Tcl_CreateTimerHandler(3) due to its relative millisecond-ness mentioning absolute time in the wall clock sense for the last 20 years, which makes CLOCK_MONOTONIC a legit time source. After all, any assumptions, that time computations using [clock seconds] et.al. applied to after(n) are correct, are IMO thus cargo-cultivated programming errors. Then there is interp(n) with its IMO wrongly designed time limit based on absolute time. But that certainly came long after after's invention. And why has it to be based on absolute time? And then there is virtualized time? And why was it? And where is it test cased in the core?
      
    2. login: "chw"
    3. mimetype: "text/plain"
  26. Ticket change [b0296458ff] (rid 161568) by chw on 2018-03-08 23:35:39:

    1. icomment:
      Another attempt to bring tip 302 somewhat forward. The another attached patch
      adds handling for the new "-at" attribute for timed after commands. The semantic
      is not like "-robust" as laid out in the tip, but instead based on the clock
      command, i.e. specifies a point in this (wall clock) time domain to make that
      fact explicit to the user. A few test cases are included as well as an update
      to the after.n man page.
      
      The patch is against core-8-6-branch and tested on Debian 9 amd64. It runs
      all tests without errors. Win32/64 is not verified.
      
    2. login: "chw"
    3. mimetype: "text/plain"
  27. Add attachment "another-tip302.patch" [c147b0a271] (rid 161569) by chw on 2018-03-08 23:36:57.

  28. Ticket change [53ed4eec30] (rid 239975) by oehhar on 2025-05-10 14:53:05:

    1. icomment:
      Merged current main by [6ff6edf427].
      Only tested on Windows.
      I was surprised, that there are still "#if TCL_THREADS" in the source.
      I thought, we nowdays always build threadded.
      
      Next step is to test and to look on Sergeys work.
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  29. Ticket change [79cced3f1c] (rid 239979) by oehhar on 2025-05-10 18:38:11:

    1. icomment:
      I have made the following test on Winddows 11 64 bit with MS-VS2022 64 bit compile of the branch:
      
      <verbatim>
      proc pt sec10 {
          puts "sec10=$sec10, clock=[expr {[clock seconds]-$::now}]"
      }
      set now [clock seconds]
      for {set sec 10} {$sec<=180} {incr sec 10} {after [expr {$sec*1000}] [list pt $sec]}
      </verbatim>
      
      Then, I start cmd.exe as Administrator and type "time" and I advance the time by 10 minuites.
      
      The results are as follows:
      
         *   TCL 9.0.1: all remaining events fire at once
         *   Bug branch: no events fire at all, there is no after event any more.
      
      So, there is something wrong with the patch...
      
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  30. Ticket change [4c2fc95930] (rid 239980) by oehhar on 2025-05-10 20:25:19:

    1. icomment:
      It was me. I forgot the "vwait forever", as it is tclsh, not wish.
      
      But for the given test below, there is no difference between the bug branch and tcl9.0.1.
      The branch does not help and apparently, the after is not independent to the wall clock.
      
      Here is the output:
      <verbatim>
      % proc pt sec10 {
          puts "sec10=$sec10, clock=[expr {[clock seconds]-$::now}]"
      }
      % set now [clock seconds]
      1746909277
      % for {set sec 10} {$sec<=180} {incr sec 10} {after [expr {$sec*1000}] [list pt $sec]}
      % vwait forever
      sec10=10, clock=12
      sec10=20, clock=22
      sec10=30, clock=32
      sec10=40, clock=42
      sec10=50, clock=623
      sec10=60, clock=623
      sec10=70, clock=623
      sec10=80, clock=623
      sec10=90, clock=623
      sec10=100, clock=623
      sec10=110, clock=623
      sec10=120, clock=623
      sec10=130, clock=623
      sec10=140, clock=623
      sec10=150, clock=623
      sec10=160, clock=623
      sec10=170, clock=623
      sec10=180, clock=623
      </verbatim>
      
      As you can see, all after events fire together, when the wall clock is advanced.
      
      Do I miss something?
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  31. Ticket change [6da2044e5c] (rid 239981) by chw on 2025-05-10 20:51:10:

    1. icomment:
      Come on Harald,
      a puts and and a flush that's all
      
    2. login: "chw"
    3. mimetype: "text/plain"
  32. Ticket change [7e4ecfeb8b] (rid 239982) by chw on 2025-05-10 21:19:01:

    1. icomment:
      Nope, I was wrong.
      Assuming that your patch is what in vanillawish works,
      the patchery went wrong. Bummer!
      
    2. login: "chw"
    3. mimetype: "text/plain"
  33. Ticket change [bba9225760] (rid 239983) by oehhar on 2025-05-11 11:44:44:

    1. icomment:
      CHristian,
      thanks for looking into this.
      Undroidwish:
      [https://ch-werner.hier-im-netz.de/LUCK/undroidwish-win64.exe]
      
      There, the test works like a charme.
      I will diff the relevant places.
      
      Here is the log from Undoidwish:
      
      <verbatim>
      % proc pt sec10 {
      > 
      >     puts "sec10=$sec10, clock=[expr {[clock seconds]-$::now}]"
      > 
      > }
      (Desktop) 2 % 
      (Desktop) 2 % set now [clock seconds]
      1746963642
      (Desktop) 3 % 
      (Desktop) 3 % for {set sec 10} {$sec<=180} {incr sec 10} {after [expr {$sec*1000}] [list pt $sec]}
      sec10=10, clock=10
      sec10=20, clock=20
      sec10=30, clock=566
      sec10=40, clock=576
      sec10=50, clock=586
      sec10=60, clock=596
      sec10=70, clock=606
      sec10=80, clock=616
      sec10=90, clock=626
      sec10=100, clock=636
      sec10=110, clock=646
      sec10=120, clock=656
      sec10=130, clock=666
      sec10=140, clock=676
      sec10=150, clock=686
      </verbatim>
      
      The after is independent on the wall clock. You see the wall-clock jump at 20, but the after continue to work with a time distance of 10.
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  34. Ticket change [d4f9d725cf] (rid 240005) by oehhar on 2025-05-13 06:00:12:

    1. icomment:
      May I ask, if undroidwish is compiled with "--with-tickcount" to disable TIP 233 [https://core.tcl-lang.org/tips/doc/trunk/tip/233.md] ?
      
      This activates different code paths...
      
      Thanks,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  35. Ticket change [8ae6ad7954] (rid 240008) by chw on 2025-05-13 07:48:54:

    1. icomment:
      Harald,
      
      yes, it is, since that's the precondition to have some monotonic clock
      on Win32 using GetTickCount64() or even GetTickCount() as a fall back
      on olden OS versions (which could be not old enough even to be recycled).
      
    2. login: "chw"
    3. mimetype: "text/plain"
  36. Ticket change [5c037beaf1] (rid 240009) by chw on 2025-05-13 07:51:22:

    1. icomment:
      And again for the record regarding TIP#233: there ain't no test
      cases in the test suite, how can we be sure that it even works?
      A section in one of the man pages is missing, too. IMO TIP#233
      should be ditched.
      
    2. login: "chw"
    3. mimetype: "text/plain"
  37. Ticket change [656516d565] (rid 240014) by oehhar on 2025-05-13 09:58:28:

    1. icomment:
      Thanks for the info.
      Commit [2e9374edd5] makes it work on MS-Windows for me.
      That is great.
      
      I have removed the Windows XP emulation.
      It did not compile for me.
      The used interface was introduced with Windows Vista.
      
      This does not allow to merge-back to TCL 8.6, as XP is supported.
      
      The issue with TIP #233 is complicated on the formal level, as this is an approved TIP. I will ask the author of the TIP (Andreas Kupries), if this is really senseful and in conformance.
      Perhaps, he is in the Telco tonight.
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  38. Ticket change [eea425c80e] (rid 259773) by serhiy.storchaka on 2026-10-21 10:53:13:

    1. foundin changed to: "9.1.0"
    2. icomment:
      On main the timers are monotonic since TIP 723, but timed condition waits on Unix still used an absolute wall-clock deadline (default <tt>CLOCK_REALTIME</tt> condition variables, deadline from <tt>Tcl_GetDayTime()</tt>). A step of the system time during a timed wait made it longer or shorter by the size of the step. This affects every timed wait, including the 0-timeout one in zipfs init.
      
      Proposed fix in branch [/timeline?r=unix-monotonic-condwait|unix-monotonic-condwait]: condition variables are created with <tt>pthread_condattr_setclock(CLOCK_MONOTONIC)</tt> where available, and deadlines are computed on the same clock. It covers <tt>Tcl_ConditionWait()</tt> and the select notifier's wait. <tt>TclUnixWaitForFile()</tt> also uses the monotonic clock now. Without <tt>pthread_condattr_setclock()</tt> (macOS), the behavior is unchanged.
      
      Tested on Linux, FreeBSD, NetBSD, OpenBSD and OpenIndiana, with the wall clock shifted by an <tt>LD_PRELOAD</tt> shim. There is no test in the suite, since that needs a clock change.
      
    3. login: "serhiy.storchaka"
    4. mimetype: "text/x-fossil-wiki"
  39. Ticket change [93b1048229] (rid 259791) by oehhar on 2026-10-21 11:47:49:

    1. icomment:
      Would be great, if a Linux expert could verify.
      On MS-Win all is ok.
      
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  40. Ticket change [1211f5a34c] (rid 259806) by serhiy.storchaka on 2026-10-21 13:39:35:

    1. icomment:
      Harald, I tested it on Linux: with the wall clock shifted 1 hour forward by an <tt>LD_PRELOAD</tt> shim, <tt>after 2000</tt> hangs with current trunk and takes 2 seconds with the branch. The full test suite passes on Linux, and the notifier, timer, thread and I/O tests on FreeBSD, NetBSD, OpenBSD, DragonFly and OpenIndiana. Windows needs no change, since its waits use relative timeouts. macOS has no <tt>pthread_condattr_setclock()</tt>, so there the behavior is unchanged; <tt>pthread_cond_timedwait_relative_np()</tt> could fix it, but I cannot test macOS.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  41. Ticket change [3e7d941e31] (rid 259807) by oehhar on 2026-10-21 13:51:03:

    1. icomment:
      Thanks. Lets give other Linux folks one week of time.
      If there is no 2nd opinion, we will merge in one week.
      
      Thanks for all,
      Harald
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"