Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ef74dbd72249d9341ae1edaeccb71d0689524d1c230ecfc55f199c18d50f7390
Ticket: 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
Nested mutexes following TIP 509
User & Date: jan.nijtmans on 2025-09-26 07:18:42
Changes

  1. closedate changed to: "2460944.80465612"
  2. closer changed to: "jan.nijtmans"
  3. icomment:
    Thanks!
    
    So we have 2 dogma's: "thy shall not use recursive mutex" and "thy shall use a single lock within a compare-and-modify operation". Here we have an example where those two rules are conflicting. In some situations the first rule is more important, in other situations the second one.
    
    That also means we have a valid use-case for recursive mutexes. For some more complicated compare-and-modify operations it might be not so easy to implement it without a recursive mutex. This one is quite easy, so I tend to agree with both Ashok and Sergey that it's best to change tclEncoding.c. This way we don't have to bother with recursive mutexes any more in the core (but it might be useful for more complicated situations in extensions).
    
    So, we could implement an internal TclMutexStrictLock() function which does the same as Tcl_MutexLock(), except it panics when it is called recursively. In order to do that we still need a Interlocked function to retrieve the "thread" field, in order to determine that. So we don't save anything at all compared to just using Tcl_MutexLock() everywhere. I don't think it's worth it, neither to export this function as Tcl_MutexStrictLock(). It would be even less worth to duplicate all mutex functions in a non-recursive and a recursive variant.
    
    Let's talk about this next meeting.
    
  4. login: "jan.nijtmans"
  5. mimetype: "text/x-fossil-wiki"