Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 706a6aee141fdbfad1a42da39bcd714b15754952
Ticket: 159a3e1dab1142775a8e1ccee3e09323d9e290de
Creating Tcl_Interp from two different threads ends up in an infinite loop
User & Date: jpo38 on 2016-05-03 06:27:30
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    I'm embedding Tcl interpreter library (8.6.5) in a C++ application. 
    
    I can't create two interpreters from two different threads. The following code ends up in an infinite loop:
    
    <code>
    #include "tcl.h"
    #include <boost/thread.hpp>
    
    void runScript()
    {
        Tcl_Interp* pInterp = Tcl_CreateInterp();
        Tcl_DeleteInterp( pInterp );
    }
    
    int main( int argc, char* argv[] )
    {
        Tcl_FindExecutable(NULL);
    
        boost::thread thrd1( runScript );
        thrd1.join();
    
        boost::thread thrd2( runScript );
        thrd2.join();
    
        return 1;
    }
    </code>
    
    Inifinite loop occures here:
    
    <code>
    void
    TclInitNotifier(void)
    {
        ThreadSpecificData *tsdPtr;
        Tcl_ThreadId threadId = Tcl_GetCurrentThread();
    
        Tcl_MutexLock(&listLock);
        for (tsdPtr = firstNotifierPtr; tsdPtr && tsdPtr->threadId != threadId;
            tsdPtr = tsdPtr->nextPtr) {
        /* Empty loop body. */
        // this loop never ends!
        }
    </code>
    
    Adding:
    <code>
    if ( tsdPtr != NULL && tsdPtr->nextPtr == tsdPtr )
    {
        tsdPtr = NULL;
        break;
    }
    </code>
    
    within the loop apparently fixes the issue.
    
    Note that I compiled Tcl with a CMake script, I noticed that TCL_THREADS is not set (not sure it's related or not)
    
  5. foundin changed to: "8.6.5"
  6. is_private changed to: "0"
  7. login: "jpo38"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "54d7c7073766af3c0b23c08dde393222d793580a"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "jpo38"
  14. subsystem changed to: "49. Threading"
  15. title changed to:
    Creating Tcl_Interp from two different threads ends up in an infinite loop
    
  16. type changed to: "Bug"