Thread package fails to consider the interp it was initially loaded from was deleted
Closed / Invalid518f1f22be08de2451152907b0136b0fe871e9ceCreated 10 years agoUpdated 10 years ago
Descriptionplain2016-06-11 14:47:02
The thread package commands call a function named Init and passes along the caller's interpreter. Init caches the interp in thread local storage if it hasn't been set yet and uses it for all future invocations. If the interp is later deleted this will lead to an error ("attempt to call eval in deleted interpreter") when communicating with its parent thread via commands like thread::send.
There is a demo of this here: http://paste.tclhelp.net/?id=idf
If this is a Won't Fix I propose the docs be updated to warn against deleting the calling interp to save someone else some pain.
Correcting the behavior seems trivial and shouldn't have any noticable performance impact. The function shown below seems to solve the problem:
static void
Init(interp)
Tcl_Interp *interp; /* Current interpreter. */
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
if (tsdPtr->interp == (Tcl_Interp*)NULL) {
memset(tsdPtr, 0, sizeof(ThreadSpecificData));
tsdPtr->interp = interp;
ListUpdate(tsdPtr);
Tcl_CreateThreadExitHandler(ThreadExitProc,
(ClientData)threadEmptyResult);
} else if (Tcl_InterpDeleted(tsdPtr->interp)) {
tsdPtr->interp = interp;
}
}
dgpplain2016-06-13 18:03:54
Resubmitted to the ticket tracker for Thread: http://core.tcl.tk/thread/tktview/4a8a7fbb1f
Log in (anonymous is fine) to add a comment.