Artifacts Associated With Ticket 159a3e1dab114277
Ticket change [706a6aee14] (rid 146610) by jpo38 on 2016-05-03 06:27:30:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized 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) - foundin initialized to: "8.6.5"
- is_private initialized to: "0"
- login: "jpo38"
- priority initialized to: "5 Medium"
- private_contact initialized to: "54d7c7073766af3c0b23c08dde393222d793580a"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "jpo38"
- subsystem initialized to: "49. Threading"
- title initialized to:
Creating Tcl_Interp from two different threads ends up in an infinite loop
- type initialized to: "Bug"
Ticket change [77e3041e3e] (rid 146611) by dgp on 2016-05-03 12:56:24:
- icomment:
TCL_THREADS=1 is the means by which Tcl is compiled to support multi-threaded use. From what you've posted, I strongly suspect that's the problem here. If you continue to have trouble with a --enable-threads build of Tcl, please post again.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- icomment:
Ticket change [97ce7eb55d] (rid 146728) by jpo38 on 2016-05-14 08:31:42:
- icomment:
@dgp Can you point me to the doc explaining how to do that? Especially where to find compatible pthread version and have it be found by build system?
- login: "jpo38"
- mimetype: "text/plain"
- icomment:
Ticket change [4787320aae] (rid 146737) by dgp on 2016-05-17 14:00:58:
- icomment:
I don't understand what you are asking. I build only with the unix subdirectory toolchain. In that build system, the --enable-threads option to configure causes Tcl to be built supporting multi-threaded operations under the "apartment model". This is the default setting in releases Tcl 8.6.0 and higher.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [4b3c2892db] (rid 146900) by jpo38 on 2016-06-06 19:27:43:
- icomment:
@dgp:TCL_THREADS was disabled because I compiled on windows using a CMake Lists.txt file I found on the web: this one was actually written for Linux and disabled thread support because it was unable to find pthread on my machine. I finally compiled Tcl libraries using the scripts provided threading is enabled by default and the infinite loop is gone! Thanks for your help!
- login: "jpo38"
- mimetype: "text/plain"
- icomment:
Ticket change [009c0e37c6] (rid 146901) by oehhar on 2016-06-07 06:37:38:
- closedate changed to: "2457546.77613545"
- closer changed to: "oehhar"
- login: "oehhar"
- mimetype: "text/plain"
- status changed to: "Closed"