Skip to content

Commit

Permalink
Fix [f32864af] - thread::eval hang
Browse files Browse the repository at this point in the history
  • Loading branch information
apnadkarni committed Dec 16, 2024
1 parent 6fb0e05 commit bcfa337
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion generic/threadSpCmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down Expand Up @@ -786,6 +788,7 @@ ThreadEvalObjCmd(
Sp_RecursiveMutexUnlock(&evalMutex);
} else {
SpMutexUnlock(mutexPtr);
PutMutex(mutexPtr);
}

return ret;
Expand Down
6 changes: 6 additions & 0 deletions tests/thread.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bcfa337

Please sign in to comment.