Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: bca3d8734a54d003664955791e1a1f9690996d46
Ticket: 1440723fffffffffffffffffffffffffffffffff
using time operation in tcl is unsafe in multithread app
User & Date: tatooguy on 2006-03-01 03:17:08
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    VERSION: 
      Tcl8.3.2
    OS Plafform:and Version:
      SunOS wapgw1 5.8 Generic_117350-22 sun4u sparc SUNW, 
    
    Brief Description about behavior:
    
       I have a multithread program in unix c++ . In one 
    thread, I create a TCl Interpreter with 
    Tcl_CreateInterp and execute the script buffer. 
    
    In some other threads I do some other things.
    
       Currently, I migrate my program from my solaris 8 
    to another solaris 8, 
    
    it often core dump abnormally if I keep on execute the 
    following two tcl sencenses.
    
     
    
    set systemTime [clock seconds];
    
    set TclVarTimeStamp [clock format $systemTime -format %
    Y-%m-%dT%H:%M:%SZ];
    
     
    
      I check the source code and find that there are many 
    functions related to time or time zone which call 
    function localtime()
    
    not localtime_r(). Although I find many mutex lock in 
    these functions, but it can only assure that all the 
    TCLInterpreter related
    
    threads can safely call this type of function, not 
    other threads.
    
     
    
      For example: a two thread app
    
      Thread1: TCLInterpreter call localtime with mutex 
    lock
    
      Thread2: some times call localtime_r
    
      then, no matter how the thread1’s tcl source code 
    lock the localtime() operation,   thread2 can also 
    access the localtime_r()
    
      since the tcl’s mutex lock have nothing to do with 
    thread2, it only take effect in tcl8.3.2 source code. 
    And when thread1 and thread2
    
      call this function at the same time, it will be 
    unsafe!!!!
    
     
    
    So, I wonder whether the tcl8.3.2 related time 
    operation is thread-safe and how to make it thread-
    safe. In the lasted version tcl8.4.12,
    
    I still find many place which call localtime() instead 
    of localtime_r().
    
     
    
    One more puzzling thing which I can’t figure out and 
    also intersting:
    
      My program was build in the Solaris OS whose system 
    TIMEZONE is PRC, while the Solaris OS which make my 
    program core
    
    is not PRC but others like Hongkong, etc. If I set the 
    TZ environment in the unix login shell and run my 
    program in the “core” OS, it runing fine. 
    
     
    
    Why??? anyone met this before and how to fix it? 
    Personly, I think the tcl’s time operation is unsafe:
    ( Does it a known bug? 
    
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "tatooguy"
  9. subsystem changed to: "None"
  10. title changed to:
     using time operation in tcl is unsafe in multithread app
    
  11. type changed to: "Bug"