From bcfa337efd51a3709d09b83db45bb057cbd817b5 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 16 Dec 2024 13:13:44 +0000 Subject: [PATCH] Fix [f32864af] - thread::eval hang --- generic/threadSpCmd.c | 5 ++++- tests/thread.test | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/generic/threadSpCmd.c b/generic/threadSpCmd.c index 7144977..d837829 100644 --- a/generic/threadSpCmd.c +++ b/generic/threadSpCmd.c @@ -713,7 +713,7 @@ ThreadEvalObjCmd( } /* - * Find out wether to use the internal (recursive) mutex + * Find out whether to use the internal (recursive) mutex * or external mutex given on the command line, and lock * the corresponding mutex immediately. * @@ -740,11 +740,13 @@ ThreadEvalObjCmd( return TCL_ERROR; } if (IsReadWrite(mutexPtr)) { + PutMutex(mutexPtr); Tcl_AppendResult(interp, "wrong mutex type, must be exclusive " "or recursive", NULL); return TCL_ERROR; } if (!SpMutexLock(mutexPtr)) { + PutMutex(mutexPtr); Tcl_AppendResult(interp, "locking the same exclusive mutex " "twice from the same thread", NULL); return TCL_ERROR; @@ -786,6 +788,7 @@ ThreadEvalObjCmd( Sp_RecursiveMutexUnlock(&evalMutex); } else { SpMutexUnlock(mutexPtr); + PutMutex(mutexPtr); } return ret; diff --git a/tests/thread.test b/tests/thread.test index e8359ca..7b2cae4 100644 --- a/tests/thread.test +++ b/tests/thread.test @@ -1250,5 +1250,11 @@ test thread-21.16 {thread::cond - delete waited variable} { list $c1 $c2 $r1 $r2 } {1 0 {condition variable is in use} {}} +test thread-bug-f32864afe3 {Hang in thread::eval -lock} -body { + set mu [thread::mutex create] + thread::eval -lock $mu {} + thread::mutex destroy $mu ; # <- Bug f32864af hang +} -result {} + removeFile dummyForTransfer ::tcltest::cleanupTests