summaryrefslogtreecommitdiffstats
path: root/generic/tclThread.c
diff options
context:
space:
mode:
authorJoe Mistachkin <joe@mistachkin.com>2015-05-17 18:03:15 (GMT)
committerJoe Mistachkin <joe@mistachkin.com>2015-05-17 18:03:15 (GMT)
commitfc49271c0a03ec5ed04419f535526f3d229929c4 (patch)
tree3604f9fd49bb4908708f3547e2bebf85ff8fd645 /generic/tclThread.c
parent1a30606518e92959f2e122f4a99a1a1c499a15a6 (diff)
downloadtcl-fc49271c0a03ec5ed04419f535526f3d229929c4.zip
tcl-fc49271c0a03ec5ed04419f535526f3d229929c4.tar.gz
tcl-fc49271c0a03ec5ed04419f535526f3d229929c4.tar.bz2
Draft fix for a potential race condition in the new Tcl_MutexUnlockAndFinalize API. Not yet tested.
Diffstat (limited to 'generic/tclThread.c')
-rw-r--r--generic/tclThread.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/generic/tclThread.c b/generic/tclThread.c
index 64e956a..db326ad 100644
--- a/generic/tclThread.c
+++ b/generic/tclThread.c
@@ -305,12 +305,17 @@ void
Tcl_MutexUnlockAndFinalize(
Tcl_Mutex *mutexPtr)
{
+ Tcl_Mutex mutex;
TclpMasterLock();
+ TclpMutexLock();
#ifdef TCL_THREADS
- Tcl_MutexUnlock(mutexPtr);
- TclpFinalizeMutex(mutexPtr);
+ mutex = *mutexPtr;
+ *mutexPtr = NULL; /* Force it to be created again. */
+ Tcl_MutexUnlock(&mutex);
+ TclpFinalizeMutex(&mutex);
#endif
- ForgetSyncObject(mutexPtr, &mutexRecord);
+ ForgetSyncObject(&mutex, &mutexRecord);
+ TclpMutexUnlock();
TclpMasterUnlock();
}