Skip to content
Tcl Source Code History Of Ticket 2172279
Login

History Of Ticket 2172279

Artifacts Associated With Ticket 2172279

  1. Ticket change [dc4087c3ad] (rid 108107) by nobody on 2008-10-16 16:46:59:

    1. assignee initialized to: "nijtmans"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      I want to write an application that is able to start and stop a tcl interpreter on demand.
      But there seems to be a problem  - when calling Tcl_FinalizeThread the application crashes !
      
      Tcl_FinalizeThread() does not accept any parameters, so if I want to finalize the Tcl thread I have to call it from the Tcl thread (using the event queue with Tcl_ThreadQueueEvent).
      When doing this a crash occurs.
      
      Tcl_FinalizeThread cleans up many data structures (queueMutex,...). But this data sttructures are neccessary to execute the following code section in Tcl_ServiceEvent. Because these data structures have been freed, Tcl tries to access a ptr 0xdddddddd.
      
      I do not think that there is a valid context to call Tcl_FinalizeThread, so please fix the bug.
      
      
      1. callstack
      
       tcl84.dll!Tcl_MutexLock(Tcl_Mutex_ * * mutexPtr=0x03922cac)  Line 500 + 0xc bytesC
       tcl84.dll!Tcl_ServiceEvent(int flags=0xfffffffd)  Line 641 + 0xc bytesC
      >tcl84.dll!Tcl_DoOneEvent(int flags=0xfffffffd)  Line 945 + 0x9 bytesC
       HmiTclSupport.dll!TclThreadMainLoop()  Line 735 + 0x1a bytesC++
       tcl84.dll!Tcl_Main(int argc=0xffffffff, char * * argv=0x03fa15e0, int (Tcl_Interp *)* appInitProc=0x03f984d0)  Line 444 + 0x8 bytesC
      
      
      2. the location the error occurs
      
      int
      Tcl_ServiceEvent(flags)
          int flags;/* Indicates what events should be processed.
       * May be any combination of TCL_WINDOW_EVENTS
       * TCL_FILE_EVENTS, TCL_TIMER_EVENTS, or other
       * flags defined elsewhere.  Events not
       * matching this will be skipped for processing
       * later. */
      {
          Tcl_Event *evPtr, *prevPtr;
          Tcl_EventProc *proc;
          int result;
          ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
      
          /*
           * Asynchronous event handlers are considered to be the highest
           * priority events, and so must be invoked before we process events
           * on the event queue.
           */
          
          if (Tcl_AsyncReady()) {
      (void) Tcl_AsyncInvoke((Tcl_Interp *) NULL, 0);
      return 1;
          }
      
          /*
           * No event flags is equivalent to TCL_ALL_EVENTS.
           */
          
          if ((flags & TCL_ALL_EVENTS) == 0) {
      flags |= TCL_ALL_EVENTS;
          }
      
          /*
           * Loop through all the events in the queue until we find one
           * that can actually be handled.
           */
      
          Tcl_MutexLock(&(tsdPtr->queueMutex));
          for (evPtr = tsdPtr->firstEventPtr; evPtr != NULL;
       evPtr = evPtr->nextPtr) {
      /*
       * Call the handler for the event.  If it actually handles the
       * event then free the storage for the event.  There are two
       * tricky things here, both stemming from the fact that the event
       * code may be re-entered while servicing the event:
       *
       * 1. Set the "proc" field to NULL.  This is a signal to ourselves
       *    that we shouldn't reexecute the handler if the event loop
       *    is re-entered.
       * 2. When freeing the event, must search the queue again from the
       *    front to find it.  This is because the event queue could
       *    change almost arbitrarily while handling the event, so we
       *    can't depend on pointers found now still being valid when
       *    the handler returns.
       */
      
      proc = evPtr->proc;
      if (proc == NULL) {
          continue;
      }
      evPtr->proc = NULL;
      
      /*
       * Release the lock before calling the event procedure.  This
       * allows other threads to post events if we enter a recursive
       * event loop in this thread.  Note that we are making the assumption
       * that if the proc returns 0, the event is still in the list.
       */
      
      Tcl_MutexUnlock(&(tsdPtr->queueMutex));
      result = (*proc)(evPtr, flags);
      -> crash::
      -> crash::
      -> crash::
      -> crash::
      -> crash::
      Tcl_MutexLock(&(tsdPtr->queueMutex));
      -> crash::
      -> crash::
      -> crash::
      -> crash::
      
      
      
      if (result) {
          /*
           * The event was processed, so remove it from the queue.
           */
      
      
      
      
      
    4. foundin initialized to: "obsolete: 8.4.19"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "nobody"
    10. subsystem initialized to: "02. Event Loops"
    11. title initialized to: "Crash when calling Tcl_FinalizeThread()"
    12. type initialized to: "Bug"
  2. Ticket change [90e765c040] (rid 120533) by nobody on 2008-10-16 23:56:53:

    1. icomment:
      it seems that TclFinalizeThreadData() called by Tcl_FinalizeThread() causes the problem
      
      
    2. login: "[email protected]"
    3. mimetype: "text/plain"
    4. username: "[email protected]"
  3. Ticket change [9652dbb383] (rid 137005) by jan.nijtmans on 2014-02-21 19:09:19:

    1. assignee changed to: "jan.nijtmans"
  4. Ticket change [a4779a2ebd] (rid 257783) by serhiy.storchaka on 2026-10-12 18:33:54:

    1. icomment:
      <code>Tcl_FinalizeThread()</code> frees all per-thread Tcl data, including the
      event queue, so it cannot be called while Tcl is still running in that thread,
      for example from an event handler: <code>Tcl_ServiceEvent()</code> uses the
      event queue after the handler returns. Leave the event loop first (e.g. set a
      flag in the handler and check it in the loop) and call
      <code>Tcl_FinalizeThread()</code> after that.
      
    2. login: "serhiy.storchaka"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Invalid"
    5. status changed to: "Closed"
  5. Ticket change [3bf31c8c12] (rid 259897) by serhiy.storchaka on 2026-10-22 17:19:24:

    1. closedate changed to: "2461326.273543252"
    2. closer changed to: "serhiy.storchaka"
    3. login: "serhiy.storchaka"