#3376 using time operation in tcl is unsafe in multithread app

obsolete: 8.3.2
closed-out-of-date
5
2007-02-09
2006-03-01
jun
No

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?

Discussion

  • Don Porter

    Don Porter - 2006-03-01

    Logged In: YES
    user_id=80530

    Assigned to the [clock]
    maintainer, but you should
    note that version 8.3.2 is
    quite old and [clock] got
    a major rewrite for 8.5, so
    your report may be too out
    of date to act on.

     
  • Don Porter

    Don Porter - 2006-03-01
    • labels: --> 06. Time Measurement
    • milestone: --> obsolete: 8.3.2
    • assigned_to: nobody --> kennykb
     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2007-02-09

    Logged In: YES
    user_id=72656
    Originator: NO

    better use of thread-safe functions is already in 8.4 and 8.5

     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2007-02-09
    • status: open --> closed-out-of-date