From 5e260a31232a7b9acdfe574c22be589295eeb538 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 21 Sep 2011 21:45:54 +0000 Subject: Revise the thread exit handling of the [testthread] command so that it properly maintains the per-process data structures even when the thread exits for reasons other than the [testthread exit] command. --- ChangeLog | 7 +++++++ generic/tclThreadTest.c | 12 +++++++++--- tests/thread.test | 1 - 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 836b43f..85119ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-09-21 Don Porter + + * generic/tclThreadTest.c: Revise the thread exit handling of the + [testthread] command so that it properly maintains the per-process + data structures even when the thread exits for reasons other than + the [testthread exit] command. + 2011-09-21 Alexandre Ferrieux * unix/tclIO.c: [Bug 3412487]: Now short reads are allowed in diff --git a/generic/tclThreadTest.c b/generic/tclThreadTest.c index 71d5a66..3345081 100644 --- a/generic/tclThreadTest.c +++ b/generic/tclThreadTest.c @@ -46,7 +46,7 @@ static Tcl_ThreadDataKey dataKey; * protected by threadMutex. */ -static ThreadSpecificData *threadList; +static ThreadSpecificData *threadList = NULL; /* * The following bit-values are legal for the "flags" field of the @@ -623,9 +623,9 @@ NewTestThread( * Clean up. */ - ListRemove(tsdPtr); - Tcl_Release(tsdPtr->interp); Tcl_DeleteInterp(tsdPtr->interp); + Tcl_Release(tsdPtr->interp); + ListRemove(tsdPtr); Tcl_ExitThread(result); TCL_THREAD_CREATE_RETURN; @@ -744,6 +744,7 @@ ListRemove( tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr; } tsdPtr->nextPtr = tsdPtr->prevPtr = 0; + tsdPtr->interp = NULL; Tcl_MutexUnlock(&threadMutex); } @@ -1148,6 +1149,11 @@ ThreadExitProc( char *threadEvalScript = clientData; ThreadEventResult *resultPtr, *nextPtr; Tcl_ThreadId self = Tcl_GetCurrentThread(); + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + + if (tsdPtr->interp != NULL) { + ListRemove(tsdPtr); + } Tcl_MutexLock(&threadMutex); diff --git a/tests/thread.test b/tests/thread.test index e818388..732f5fd 100644 --- a/tests/thread.test +++ b/tests/thread.test @@ -70,7 +70,6 @@ test thread-1.5 {Tcl_ThreadObjCmd: thread create one shot} {thread} { set l } {1} test thread-1.6 {Tcl_ThreadObjCmd: thread exit} {thread} { - threadReap thread::create {{*}{}} update after 10 -- cgit v0.12