<i>Nested mutexes following TIP 509</i> status still Closed with 5 other changes
by
.
D 2025-10-03T11:06:34.288
J closedate 2460951.96289685
J closer jan.nijtmans
J icomment >\sSo\sthe\sconclusion\sis\sthat\swe\sdo\snot\sneed\satomic\sreads\sfor\sthe\stests.\r\n\r\nI\sshare\sthat\sconclusion,\sbut\slet's\selaborate.\r\n\r\nWe\scan\ssee\sthe\spMutex->thread\svariable\sas\sa\sstate\smachine.\sWhen\sthread\sMM\sdoes\ssome\soperation\safter\sthread\sYY,\sthe\sstate\stransitions\sare:\r\n\r\n\s\s\s\s00\s=>\sMM\s=>\s00\s=>\sYY\s=>\s00\r\n\r\nNow\stake\sinto\saccount,\sthat\sthe\spMutex->thread\svariable\sis\snot\swritten\satomically,\sthen\swe\scould\shave:\r\n\r\n\s\s\s\s00\s=>\s0M\s=>\sMM\s=>\sM0\s=>\s00\s=>\s0Y\s=>\sYY\s=>\sY0\s=>\s00\r\n\r\nThat's\sa\slot\smore\sstates\sto\sconsider.\sNow\sconsider\show\sthread\sMM\ssees\sthis.\sWithin\sthe\ssame\sthread,\sthe\sprocessor\salways\sguarantees\sthat\soperations\sinvolving\sthe\ssame\smemory\sare\salways\skept\sin\sorder.\sWhen\sthread\sMM\ssets\sthe\spMutex->thread\svariable\sto\s'MM'\sand\slater\sto\s'00',\sit\swill\snever\ssee\sthe\sintermediate\sstates\sas\sother\sthreads\smight\ssee\sthem.\sSo,\swe\sget:\r\n\r\n\s\s\s\s00\s=>\sMM\s=>\s00\s=>\s0Y\s=>\sYY\s=>\sY0\s=>\s00\r\n\r\nNow\sthe\sonly\ssituation\sleft\swe\shave\sto\sworry\sabout\sis\swhen\sthread\sMM\stries\sto\sacuire\sthe\slock.\sBefore\sthat,\sit\shas\sto\scheck\sthat\spMutex->thread\s==\s'MM',\sthen\sit\salready\shas\sthe\slock.\sBut\sthe\sstates\s'00',\s'0Y',\s'YY'\sand\s'Y0'\sare\sall\snot\sequal\sto\s'MM'.\sSo\sit\sdoesn't\sreally\smatter\swhether\sthread\sMM\ssees\sthe\sintermediate\sstates,\sthe\sresult\sof\sthe\s==\soperator\sstays\sthe\ssame.\r\n\r\nThe\sconclusion\sis\sthat\swe\sdon't\sneed\sthe\satomic\sstates\sfor\sthe\sreads.\r\n\r\nI\salso\schanged\sthe\scode\sto\suse\sTHREAD_NULL\sand\spthread_equal(),\sas\ssuggested.\r\n\r\nSee:\s[8d7d7b1c144bfca2|here]\r\n\r\nAshok's\stestcases\salready\ssucceed:\s[https://github.com/tcltk/tcl/actions/runs/18186353547]!
J login jan.nijtmans
J mimetype text/x-fossil-wiki
K 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
U jan.nijtmans
Z 3bff62208a03fc87bc9fc57fd8db95d1