Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-08-22
07:04 • Closed ticket [f23d040b9b]: application hangs in TclInitNotifier using TCL 8.5.1... artifact: 3759d339e4 user: jan.nijtmans
2016-06-07
06:37 • Closed ticket [159a3e1dab]: Creating Tcl_Interp from two different threads ends ... artifact: 009c0e37c6 user: oehhar
2016-06-06
19:27 • Ticket [159a3e1dab]: 3 changes artifact: 4b3c2892db user: jpo38
2016-05-17
14:00 • Ticket [159a3e1dab]: 3 changes artifact: 4787320aae user: dgp
2016-05-14
08:31 • Ticket [159a3e1dab]: 3 changes artifact: 97ce7eb55d user: jpo38
2016-05-03
12:56 • Pending ticket [159a3e1dab]. artifact: 77e3041e3e user: dgp
06:27 • New ticket [159a3e1dab]. artifact: 706a6aee14 user: jpo38

Creating Tcl_Interp from two different threads ends up in an infinite loop

Closed / Invalid159a3e1dab1142775a8e1ccee3e09323d9e290deCreated 11 years agoUpdated 10 years ago
Descriptionwiki2016-05-03 06:27:30
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:

#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; }

Inifinite loop occures here:

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! }

Adding: if ( tsdPtr != NULL && tsdPtr->nextPtr == tsdPtr ) { tsdPtr = NULL; break; }

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)

dgpplain2016-05-03 12:56:24
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.
jpo38plain2016-05-14 08:31:42
@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?
dgpplain2016-05-17 14:00:58
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.
jpo38plain2016-06-06 19:27:43
@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!
oehhar Closed ticket [159a3e1dab]. [History diff]2016-06-07 06:37:38
Log in (anonymous is fine) to add a comment.