Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a1bd4639a4f469d44a870664bcf0ce8913fd9202578bc4c16d0467be8a06ce5b
Ticket: 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
Nested mutexes following TIP 509
User & Date: chw on 2025-08-24 19:29:04
Changes

  1. icomment:
    Harald, I cannot attend tomorrow, so let me try to describe the
    current situation with this example:
    
      Tcl_MutexLock(&mutex);   /* A */
      Tcl_MutexLock(&mutex);   /* B */
      while (something) {
          Tcl_ConditionWait(&cond, &mutex);   /* C */
      }
      Tcl_MutexUnlock(&mutex); /* D */
      Tcl_MutexUnlock(&mutex); /* E */
    
    1) For POSIX with native recursive option:
    
    * step C decrements the lock only by one
    * this means the critical section remains locked
    * and most likely the wake up can never happen due to the lock
    * deadlock is the outcome
    
    2) For POSIX with emulated recursion counter:
    
    * step C releases the mutex without accounting for the lock count
    * the critical section is unlocked
    * the wake up can happen
    * after wake up the critical section is locked again
    * but the bookkeeping of the ownership and the lock count get lost
    * bad things happen later
    
    3) For Win32 see 1)
    
    Both patches for POSIX emulated 2) and Win32 3) try to fix the
    bookkeeping at the end of Tcl_ConditionWait() and would allow for
    a natural expected behavior.
    
    But POSIX native in 1) cannot be fixed at all.
    
  2. login: "chw"
  3. mimetype: "text/plain"