.
D 2001-07-29T11:13:03
J assignee nobody
J cmimetype text/plain
J comment The\sTcl_MutexLock\sbehaviour\sis\snot\sconsistent\nbetween\sWindows\sand\sUnix/Linux.\sI\sam\susing\sthe\nlatest\ssources\s(as\sof\syesterday)\son\sRedHat\s7.1\n\nOn\sWindows,\sif\sa\sgiven\sthread\sown\sa\slock,\srepeated\nrequests\sto\sthe\ssame\slock\sare\sgranted\swithout\na\sdeadlock\s(this\sis\sthe\sbehavior\sof\sthe\nEnterCriticalSection()).\sThis\sis\sa\svery\shandy\nfeature\sand\salmost\salways\sis\sdesirable.\n\nHowever,\son\sLinux/Unix\sby\sdefault\sthis\sis\snot\strue.\nSuch\sa\smutex\scan\sbe\screated\son\sUnix\showever\sby\nexplicitly\sasking\sfor\sit.\n\nNote:\sWith\sthe\scurrent\ssources\s(as\sof\syesterday),\nitcl\sdeadlocks\s(I\shave\ssubmitted\sa\spatch\sto\sthem\nas\swell)\swhenever\san\sobject\sis\sdeleted.\n\nThe\sfollowing\sis\smy\simplementation\s(note\sthat\nthe\slinux\sheaders\sfor\spthread\sare\sbroken\sso,\sI\nhad\sto\sworkaround\sit)\n\nvoid\nTcl_MutexLock(mutexPtr)\n\s\s\s\sTcl_Mutex\s*mutexPtr;/*\sReally\s(pthread_mutex_t\s**)\s*/\n{\n\s\s\s\spthread_mutex_t\s*pmutexPtr;\n\s\s\s\spthread_mutexattr_t\sattr\s;\n\n\s\s\s\s/*\sThe\slinux\spthread\sheaders\sdo\snot\shave\sthis\nfunction\salthough\sit\n\s\s\s\s\s\s\sexists\sin\sthe\spthread\slibrary\sand\sit\sworks\n\s\s\s\s\s\s\sas\sdocumented\s*/\n\s\s\s\sEXTERN\sint\spthread_mutexattr_setkind_np\n_ANSI_ARGS_((pthread_mutexattr_t\s*attr,\sint\skind));\n\n\s\s\s\sif\s(*mutexPtr\s==\sNULL)\s{\nMASTER_LOCK;\nif\s(*mutexPtr\s==\sNULL)\s{\n\s\s\s\s/*\s\n\s\s\s\s\s*\sDouble\sinside\smaster\slock\scheck\sto\savoid\sa\srace\ncondition.\n\s\s\s\s\s*/\n\s\s\s\spmutexPtr\s=\s(pthread_mutex_t\n*)ckalloc(sizeof(pthread_mutex_t));\n\s\s\s\spthread_mutexattr_init(&attr)\s;\n\s\s\s\spthread_mutexattr_setkind_np(&attr,\nPTHREAD_MUTEX_RECURSIVE_NP)\s;\n\s\s\s\spthread_mutex_init(pmutexPtr,\s&attr);\n\s\s\s\s*mutexPtr\s=\s(Tcl_Mutex)pmutexPtr;\n\s\s\s\spthread_mutexattr_destroy(&attr)\s;\n\s\s\s\sTclRememberMutex(mutexPtr);\n}\nMASTER_UNLOCK;\n\s\s\s\s}\n\s\s\s\spmutexPtr\s=\s*((pthread_mutex_t\s**)mutexPtr);\n\s\s\s\spthread_mutex_lock(pmutexPtr);\n}\n\n\nHere\sis\sthe\sitcl\scode\sthat\sshows\sthis\sdeadlock\n##########################\npackage\srequire\sItcl\s3.2\nputs\s"Start"\n::itcl::class\sMyBaseClass\s{\n\s\s\s\sconstructor\s{}\s{\nputs\s"MyBaseClass::constructor"\n\s\s\s\s}\n\s\s\s\sdestructor\s{\nputs\s"MyBaseClass::destructor"\n\s\s\s\s}\n}\n\nset\sinst\s[MyBaseClass\s\\#auto]\n::itcl::delete\sobject\s$inst\nputs\s"Done"\n
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter haneef
J subsystem 49.\sThreading
J title Tcl\smutexes\sbehaviour\snot\sconsistent
J type Bug
K 445672ffffffffffffffffffffffffffffffffff
U haneef
Z 69ac5952145098cb341a8a734a77d737