TIP: 435 Title: Safe Mutex Disposal API Version: $Revision: 1.7 $ Author: Donal Fellows Author: Joe Mistachkin State: Rejected Type: Project Tcl-Version: 8.6.5 Vote: Done Created: 16-May-2015 Post-History: ~ Abstract This TIP proposes a new C API for improving mutex deletion. ~ Rationale Context: Bug #57945b574a There is a race condition in the code that disposes of mutexes, in that a mutex must only be disposed of when it is not in use by another thread, yet the disposal code does not lock it. This would not be a particular problem as there is a ''global'' lock that protects the disposal code, except that during the cleanup immediately after a fork (during the '''exec''' command, for example) things can get deeply confused, and trigger deadlocks under heavy load. We need to be careful and make sure that we really hold the global lock when unlocking and disposing mutexes. Because the pipeline-opening code isn't the only thing that might ever fork internally, we should provide the capability to do this correctly as part of Tcl's public API. ~ Specification This TIP specifies a single new function: > void '''Tcl_MutexUnlockAndFinalize'''(Tcl_Mutex *''mutex''); The '''Tcl_MutexUnlockAndFinalize''' function (which takes a single argument, the mutex to operate on) will atomically unlock the mutex and dispose of it without giving an opportunity for another thread to lock the mutex between unlocking and disposal. The mutex must have previously been locked by '''Tcl_MutexLock'''. ~ Implementation See branch bug-57945b574a. ~ Acknowlegement Thanks to Gustaf Neumann for his trouble tracking this down, and apologies for the problems the fault has caused him. ~ Copyright This document has been placed in the public domain.