Skip to content

Commit 9be1c4b

Browse files
committed
Fix [f32864af] - thread::eval hang
2 parents cda9c6f + bcfa337 commit 9be1c4b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

generic/threadSpCmd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ ThreadEvalObjCmd(
709709
}
710710

711711
/*
712-
* Find out wether to use the internal (recursive) mutex
712+
* Find out whether to use the internal (recursive) mutex
713713
* or external mutex given on the command line, and lock
714714
* the corresponding mutex immediately.
715715
*
@@ -736,11 +736,13 @@ ThreadEvalObjCmd(
736736
return TCL_ERROR;
737737
}
738738
if (IsReadWrite(mutexPtr)) {
739+
PutMutex(mutexPtr);
739740
Tcl_AppendResult(interp, "wrong mutex type, must be exclusive "
740741
"or recursive", (void *)NULL);
741742
return TCL_ERROR;
742743
}
743744
if (!SpMutexLock(mutexPtr)) {
745+
PutMutex(mutexPtr);
744746
Tcl_AppendResult(interp, "locking the same exclusive mutex "
745747
"twice from the same thread", (void *)NULL);
746748
return TCL_ERROR;
@@ -782,6 +784,7 @@ ThreadEvalObjCmd(
782784
Sp_RecursiveMutexUnlock(&evalMutex);
783785
} else {
784786
SpMutexUnlock(mutexPtr);
787+
PutMutex(mutexPtr);
785788
}
786789

787790
return ret;

tests/thread.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,11 @@ test thread-22.1 {thread::send -command} {
12631263
set result
12641264
} hello
12651265

1266+
test thread-bug-f32864afe3 {Hang in thread::eval -lock} -body {
1267+
set mu [thread::mutex create]
1268+
thread::eval -lock $mu {}
1269+
thread::mutex destroy $mu ; # <- Bug f32864af hang
1270+
} -result {}
12661271

12671272
removeFile dummyForTransfer
12681273
::tcltest::cleanupTests

0 commit comments

Comments
 (0)