Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: dc4087c3ad5e7506b2aa87be72e67902fc8b28ad
Ticket: 2172279fffffffffffffffffffffffffffffffff
Crash when calling Tcl_FinalizeThread()
User & Date: nobody on 2008-10-16 16:46:59
Changes

  1. assignee changed to: "nijtmans"
  2. cmimetype changed to: "text/plain"
  3. comment changed 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 changed to: "obsolete: 8.4.19"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "nobody"
  10. subsystem changed to: "02. Event Loops"
  11. title changed to: "Crash when calling Tcl_FinalizeThread()"
  12. type changed to: "Bug"