Skip to content
Tcl Source Code History Of Ticket 1160057
Login

History Of Ticket 1160057

Artifacts Associated With Ticket 1160057

  1. Ticket change [184f572719] (rid 122638) by s_a_white on 2005-03-09 17:49:25:

    1. assignee initialized to: "andreas_kupries"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Am trying to determine what may be going on in tcl that
      causes this code to crash.  Using a main instead of tcl
      to run the code it appears to work fine.
      
      The computer is running MandrakeLinux 10.1:
      
      kernel: 2.6.8.1-12mdksmp
      gcc: 3.4.3-1mdk
      glibc: 2.3.3-21mdk
      tcl: 8.4.5-6mdk
      
      Code:
      
      #include <stdint.h>
      #include <stdio.h>
      #include <pthread.h>
      #include <unistd.h>
      #include <tcl.h>
      
      class Message
      {
      public:
         Message();
         ~Message ();
      };
      
      Message::Message() {}
      Message::~Message () {}
      
      static void *RecallTaskEntry(void *_this)
      {
         Message m;
         usleep(2000000);
         return 0;
      }
      
      extern "C" int createThread() {
        pthread_t Recallthread;
        pthread_create(&Recallthread,NULL,RecallTaskEntry, 0);
        usleep (50000);
        pthread_cancel (Recallthread);
        pthread_join   (Recallthread, NULL);
        return 0;
      }
      
      int TclCreateThread (ClientData clientData, Tcl_Interp
      *interp,
                           int argc,CONST84 char *argv[])
      {
        createThread ();
        return TCL_OK;
      }
      
      extern "C" int Thread_Init(Tcl_Interp *interp) {
         
      Tcl_CreateCommand(interp,"createThread",TclCreateThread,
      0, 0);
          return TCL_OK;
      }
      
      extern "C" int Thread_SafeInit(Tcl_Interp *interp) {
         return (Thread_Init(interp));
      }
      
      Code is C++ compiled as a shared library and run in tcl
      via:
      
      load libThread.so
      createThread
      
      The observed beviour is a segfault which results from
      doing a pthread_cancel when the thread is in the
      usleep.  The debugger output looks a little confused
      like possible stack corruption.  However as explained
      it works ok standalone outside of tcl.
      
      Things that seem to make it work are:
      
      - Removing the Message object from the thread.
      - Removing Messages destructor.
      - As a test using sleep and pause instead of usleep
      appear to work.
      
      Any ideas on what is causing this bug?
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "s_a_white"
    9. subsystem initialized to: "49. Threading"
    10. title initialized to: "Seg fault from usleep"
    11. type initialized to: "Bug"
  2. Ticket change [c928b1a78f] (rid 122236) by nobody on 2005-03-11 05:42:19:

    1. icomment:
      Logged In: NO 
      
      Have updated tcl to 8.4.9 and rebuilt the code.  Ran it up
      using tclsh (didn't update tk) and still the seg fault
      appears.  Interestingly I tried valgrind on tclsh and get
      various complaints about mallocs/free's, but the seg fault
      disappeared, hmmm.
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  3. Ticket change [adebc9146d] (rid 101540) by dkf on 2005-03-13 14:01:36:

    1. foundin changed to: "obsolete: 8.4.9"
  4. Ticket change [c23a910c3e] (rid 111456) by nobody on 2005-03-13 17:20:44:

    1. icomment:
      Logged In: NO 
      
      Additional things I've tried that had no effect, and still
      resulted in a segfault.
      
      -Updating glibc to offical release 2.3.4
      -Updating kernel to to official release 2.6.11.2
      
      Haven't yet updated the compiler as no newer official releases.
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  5. Ticket change [9626cb104c] (rid 106275) by dkf on 2005-03-14 07:51:24:

    1. priority changed to: "8"
  6. Ticket change [eccfe39004] (rid 103769) by s_a_white on 2005-09-21 16:59:53:

    1. icomment:
      Logged In: YES 
      user_id=59929
      
      This appears to be somehow exception related.  Compiling
      with -fno-exceptions prevents the segfault.
      
      
    2. login: "s_a_white"
    3. mimetype: "text/plain"
    4. username: "s_a_white"
  7. Ticket change [a09049dda8] (rid 96834) by hobbs on 2005-10-05 12:31:25:

    1. closedate changed to: "2005-10-05T05:31:25"
    2. closer changed to: "hobbs"
    3. icomment:
      Logged In: YES 
      user_id=72656
      
      Is this a possible compiler bug?  Are you making sure to
      compile Tcl with --enable-threads?  I'm not sure how this
      really relates to Tcl, vs. being a C++ issue.
      
      
    4. login: "hobbs"
    5. mimetype: "text/plain"
    6. status changed to: "Pending"
    7. username: "hobbs"
  8. Ticket change [8bdcd69b46] (rid 127649) by s_a_white on 2005-10-05 14:48:18:

    1. icomment:
      Logged In: YES 
      user_id=59929
      
      Am not sure...  The problem only started when moving to a
      newer Linux distribution and as yet have not been able to
      try a new one.  The compiler has gone from gcc 3.3 to 3.4
      (last distribution used the old compiler).
      
      I believe 3.4 is still consider "stable" and gcc 4 what to
      start aiming for but may contain bugs,  The major thing I
      note about this Linux distribution was the change to ntpl
      which was causing various other problems for us (mainly how
      thread cancelation was now being handled during cout.... now
      exception rather than cancelation point, sem_wait can now
      also return -1... not according to the docs).
      
      To be honest I wasn't sure which list to ask TCL, glibc, C++
      or gcc (note I've tried contacting glibc as they do the
      nptl, but no response).  As noted the problem only appears
      when run in TCL, rather than a standalone main.  As stated
      running tcl under valgrind with the same test made the
      problem disappear.
      
      Am I running with threads enabled, probably not.  This is a
      prebuilt version by the distribution.  All TCL does is make
      calls to external functions that start/stop threads and
      occasionally grab mutexs, but those threads do not access
      any tcl functions or keep track of any tcl memory (objects).
      
      
    2. login: "s_a_white"
    3. mimetype: "text/plain"
    4. status changed to: "Open"
    5. username: "s_a_white"
  9. Ticket change [e007c1acf6] (rid 115119) by hobbs on 2005-10-05 15:05:06:

    1. icomment:
      Logged In: YES 
      user_id=72656
      
      Reducing prio as I'm still suspicious that Tcl is at fault here.
      
      
    2. login: "hobbs"
    3. mimetype: "text/plain"
    4. priority changed to: "4"
    5. username: "hobbs"
  10. Ticket change [11a309147f] (rid 257741) by serhiy.storchaka on 2026-10-12 13:47:05:

    1. icomment:
      I cannot reproduce this with 8.6.18 and 9.1 (glibc 2.43, g++ 15): the extension
      from the report, built against them, survives 20 cancellations of the thread during
      <code>usleep()</code> with the C++ destructor on its stack. The crash was most likely
      in the reported environment: a Tcl built without threads and a glibc whose
      <code>pthread_cancel</code> unwinds the stack and needs libpthread to be loaded at
      startup; a Tcl built without threads works with the current glibc. Tcl is threaded
      by default since 8.6, and glibc includes libpthread in libc since 2.34.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
  11. Ticket change [e68b9a4acb] (rid 257742) by serhiy.storchaka on 2026-10-12 13:47:05:

    1. login: "serhiy.storchaka"
    2. resolution changed to: "Works For Me"
    3. status changed to: "Pending"