Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 509277a8f31b7ac53ce23941a02701735b76e3a4
Ticket: 445672ffffffffffffffffffffffffffffffffff
Tcl mutexes behaviour not consistent
User & Date: haneef on 2001-07-29 11:13:03
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    The Tcl_MutexLock behaviour is not consistent
    between Windows and Unix/Linux. I am using the
    latest sources (as of yesterday) on RedHat 7.1
    
    On Windows, if a given thread own a lock, repeated
    requests to the same lock are granted without
    a deadlock (this is the behavior of the
    EnterCriticalSection()). This is a very handy
    feature and almost always is desirable.
    
    However, on Linux/Unix by default this is not true.
    Such a mutex can be created on Unix however by
    explicitly asking for it.
    
    Note: With the current sources (as of yesterday),
    itcl deadlocks (I have submitted a patch to them
    as well) whenever an object is deleted.
    
    The following is my implementation (note that
    the linux headers for pthread are broken so, I
    had to workaround it)
    
    void
    Tcl_MutexLock(mutexPtr)
        Tcl_Mutex *mutexPtr;/* Really (pthread_mutex_t **) */
    {
        pthread_mutex_t *pmutexPtr;
        pthread_mutexattr_t attr ;
    
        /* The linux pthread headers do not have this
    function although it
           exists in the pthread library and it works
           as documented */
        EXTERN int pthread_mutexattr_setkind_np
    _ANSI_ARGS_((pthread_mutexattr_t *attr, int kind));
    
        if (*mutexPtr == NULL) {
    MASTER_LOCK;
    if (*mutexPtr == NULL) {
        /* 
         * Double inside master lock check to avoid a race
    condition.
         */
        pmutexPtr = (pthread_mutex_t
    *)ckalloc(sizeof(pthread_mutex_t));
        pthread_mutexattr_init(&attr) ;
        pthread_mutexattr_setkind_np(&attr,
    PTHREAD_MUTEX_RECURSIVE_NP) ;
        pthread_mutex_init(pmutexPtr, &attr);
        *mutexPtr = (Tcl_Mutex)pmutexPtr;
        pthread_mutexattr_destroy(&attr) ;
        TclRememberMutex(mutexPtr);
    }
    MASTER_UNLOCK;
        }
        pmutexPtr = *((pthread_mutex_t **)mutexPtr);
        pthread_mutex_lock(pmutexPtr);
    }
    
    
    Here is the itcl code that shows this deadlock
    ##########################
    package require Itcl 3.2
    puts "Start"
    ::itcl::class MyBaseClass {
        constructor {} {
    puts "MyBaseClass::constructor"
        }
        destructor {
    puts "MyBaseClass::destructor"
        }
    }
    
    set inst [MyBaseClass \#auto]
    ::itcl::delete object $inst
    puts "Done"
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "haneef"
  9. subsystem changed to: "49. Threading"
  10. title changed to: "Tcl mutexes behaviour not consistent"
  11. type changed to: "Bug"