<i>Nested mutexes following TIP 509</i> status still Closed with 5 other changes
by
.
D 2025-10-01T12:06:19.081
J closedate 2460950.00438751
J closer chw
J icomment Now\slemme\srefine\smy\sreasoning:\r\n\r\n0.\sWe\sunderstand\sfrom\sthe\sopengroup.org\sexplanation,\sthat\sboth,\smutex\slock\sand\sunlock\soperations\sperform\ssome\smemory\sbarrier\sor\sfence\smagic\sto\sensure\smemory\sconsistency\sof\sthe\smemory\sprotected\sby\sthe\smutex.\r\n\r\n1.\sThen\sin\sour\smutex\sinit\sfunction\swe\scan\sdo\s\s\r\n\s\s\spthread_init();\s\s\r\n\s\s\spthread_mutex_lock();\s\s\r\n\s\s\sset\sthread\sid\sto\sPTHREAD_NULL\s\s\r\n\s\s\sset\scounter\sto\s0\s\s\r\n\s\s\spthread_mutex_unlock();\s\s\r\n\r\n2.\sWe\shave\sensured,\sthat\sour\shome\sgrown\smutex\sis\susable\sonly\safter\sits\sinit\sfunction\shas\scompleted.\sTherefore\sthe\sthread\sid\sin\sour\sfreshly\sinitialized\smutex\sis\ssafely\sset\sto\sPTHREAD_NULL.\r\n\r\n3.\sIn\sour\smutex\slock\sfunction\swe\stest\sthe\sthread\sid\sof\sthe\smutex\sagainst\sour\sown\sthread\sid.\sThis\sneed\snot\sbe\satomic\ssince\swe\sguarantee\sthat\swe\swrite\sthe\smutexes'\sthread\sid\sonly\swhen\swe\sreally\slocked\sthe\snative\smutex.\r\n\r\n4.\sIn\sour\smutex\sunlock\sfunction\swe\swrite\sthe\smutexes'\sthread\sid\sto\sPTHREAD_NULL\sbefore\swe\sunlock\sthe\snative\smutex\sto\sindicate\sthat\swe\sgave\sup\sownership.\r\n\r\nWhen\sthe\smutexes'\sthread\sid\sis\sread\sunlocked\sfor\stesting\sof\sownership,\sit\sthus\scan\shave\sthese\sthree\spossible\svalues:\r\n\r\n1.\sPTHREAD_NULL\r\n2.\sown\sthread\sid\r\n3.\ssome\sother\sthread\sid\r\n\r\nThe\stest\sin\slock\sand\sunlock\s(and\sin\sthe\scondition\svariable\scases)\slooks\sfor\sthe\smutexes'\sthread\sid\sbeing\sequal\sto\sour\sown\sthread\sid\s(which\simplies\sthat\swe\shold\sthe\snative\smutex)\sor\sanything\selse\sincluding\sPTHREAD_NULL.\r\n\r\nSo\sthe\sconclusion\sis\sthat\swe\sdo\snot\sneed\satomic\sreads\sfor\sthe\stests.\r\n\r\nOther\sthan\sthat,\sto\senhance\sportability,\splease\suse\spthread_equal()\sfor\stesting\sthread\sids\sand\suse\sPTHREAD_NULL\s(with\san\sown\sdefinition\sto\s0\sif\sneeded)\sinstead\sof\sassigning\s0\sdirectly.
J login chw
J mimetype text/x-markdown
K 893f8cc5db3ba8bd6bed80ce89a0a75c6088a37c
U chw
Z 280dff549a5ad379cfe89389f7f33d85