TIP #435: SAFE MUTEX DISPOSAL API =================================== Version: $Revision: 1.7 $ Author: Donal Fellows Joe Mistachkin State: Rejected Type: Project Tcl-Version: 8.6.5 Vote: Done Created: Saturday, 16 May 2015 URL: https://tip.tcl-lang.org435.html 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. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows