Skip to content
Tcl Source Code Artifact [55d85e623b]
Login

Artifact [55d85e623b]

Artifact 55d85e623b72bcd76a03f3cf8cac1fb1e098194a7f61f1266588b4fed4645bf8:

Ticket change [55d85e623b] - Ticket [893f8cc5db3ba8bd|893f8cc5db] <i>Nested mutexes following TIP 509</i> status still Closed with 5 other changes by sebres on 2025-09-26 10:19:36.
D 2025-09-26T10:19:36.217
J closedate 2460944.93028029
J closer sebres
J icomment <blockquote>>\sStill,\sin\sthis\scase\sno\sharm\sis\sdone\sbecause\seven\sin\sthe\svery\sunlikely\scase\sthis\shappens,\sthe\sonly\seffect\sis\sa\sneedless\sencoding\schange\sand\sepoch\sbump.</blockquote>\r\n\r\nOr\svice\sversa,\sit\smay\snot\sdetect\sthe\schange\sof\sencoding\sby\sanother\sthread,\sbut\sthen,\sit'd\sreturn\sbefore\slock\s(and\sthink\sthe\sencoding\sis\sstill\sthe\ssame\sas\sgiven).\r\nBoth\seffects\sare\ssimple\sa\stiming\sissue\sand\sa\slock\shas\snothing\sto\sdo\swith\sthat.\sFew\snanoseconds\searlier\sor\slater\sit'd\sbehave\sdifferent\sand\sthe\slast\sthread\swins\shere,\sno\smatter\swith\sor\swithout\slock.\r\n\r\n<blockquote>>\sSo\swe\shave\s2\sdogma's:\s"thy\sshall\snot\suse\srecursive\smutex"\sand\s"thy\sshall\suse\sa\ssingle\slock\swithin\sa\scompare-and-modify\soperation".\s</blockquote>\r\n\r\nNo.\sThe\s"usage\sof\ssingle\slock"\sis\smostly\sthe\ssame\sas\s"not\suse\srecursive\smutex"...\sin\sthat\sparticular\scase\sit'd\sbe\senough\sto\sprovide\sGetEncoding()\swithout\slock\s(in\sopposite\sto\sTcl_GetEncoding(),\ssimilar\sto\sFreeEncoding()/Tcl_FreeEncoding()\spair)\sand\suse\sthat\sGetEncoding\swithin\sthe\ssingle\slock\sinside\sTcl_SetSystemEncoding.\sBut\sas\salready\sconvinced\s-\sunneeded\shere,\sbecause\sthere\sis\sno\sharm\sat\sall.\r\n\r\nRecursive\smutex\scan\sbe\sonly\sneeded\sif\sin\ssome\scase\sis\stoo\shard\sto\spredict\swhether\smutex\swas\salready\slocked\sby\scurrent\sthread\sor\snot.\s99.99%\sof\sany\scases\smay\sbe\srewritten\sto\sguarantee\sthat,\sespecially\sif\sone'd\skeep\sin\smind\sthat\sto\sbe\soptimal\sa\slock\smust\sbe\sas\sshort\sas\spossible,\swhat\sis\scontradicting\swith\sa\srecursion\sa\sbit.\sYes,\sthere\sare\ssurely\scases\swhere\sa\srecursion\sshall\sbe\sprotected\sby\smutex,\sbut\sit\sis\snever\sunavoidable,\sso\seither\sit\scan\sbe\sprotected\sonce\sat\sfirst\slevel\s(or\soutside)\sor\smuch\sbetter\sunfolded\sto\scycle\sor\sdata\sitems\ssomehow\smarked\sas\sbusy\son\severy\siteration...\sThere\sare\smany\sknown\sprogramming\spatterns\sto\sachieve\sthat.\r\n\r\n<blockquote>>\swe\scould\simplement\san\sinternal\sTclMutexStrictLock()\sfunction\swhich\sdoes\sthe\ssame\sas\sTcl_MutexLock(),\sexcept\sit\spanics\swhen\sit\sis\scalled\srecursively.</blockquote>\r\n\r\nWell,\sthe\simplementation\slike\sthis\swould\sget\sall\scons\sof\srecursive\smutex\sand\shas\sno\spros\sat\sall,\sexcepting\sa\spossible\spanic\sinstead\sof\shang\sin\scase\sof\snesting\sinvocation.\sThe\sidea\sis\snot\sbad,\sbut\sfor\sdebug\s(+\sassert)\smode\smaybe.\r\n\r\nAnyway,\sI\sthink\sthe\sbest\swe\scan\sdo\swould\sbe\sto\srevert\severything\sto\snon-recursive\smutexes\sand\sto\sprovide\srecursive\smutexes\sas\snew\sAPI,\se.\sg.\slike\sTcl_RecMutexLock()\s/\sTcl_RecMutexUnlock().\sBut,\sas\salready\ssaid\sit\sis\ssomething\soutside\sof\sbest\spractice\sand\sthe\spercent\sof\sreal\suse-cases\sfor\sthat\sare\sso\smeasly,\sand\sif\sreally\sneeded\scan\sbe\salmost\salways\sachieved\son\suser\sside\swithout\sto\shave\sreentrant\smutexes.
J login sebres
J mimetype text/x-fossil-wiki
K 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
U sebres
Z f1592c1a42b467dc60c6a9c65d576da8