<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">On 13/04/2022 06.56, [EXT] 王斌 wrote:<br>
</div>
<blockquote type="cite"
cite="mid:a93f01134ae0421487af7c9dfd8c3893@ylex-mbx04.yealink.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:等线;
panose-1:2 1 6 0 3 1 1 1 1 1;}@font-face
{font-family:"\@等线";
panose-1:2 1 6 0 3 1 1 1 1 1;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:等线;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:21.0pt;
font-size:10.5pt;
font-family:等线;}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:等线;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;}div.WordSection1
{page:WordSection1;}ol
{margin-bottom:0cm;}ul
{margin-bottom:0cm;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi</span>:<span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">See lock_hash in
h_table.c:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Flowing lines of code do
not guarantee atomicity and I think it is not safe:<o:p></o:p></span></p>
<p class="MsoListParagraph"
style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0
level1 lfo4">
<!--[if !supportLists]--><span lang="EN-US"><span
style="mso-list:Ignore">-<span style="font:7.0pt
"Times New Roman"">
</span></span></span><!--[endif]--><span lang="EN-US">atomic_get(&_tm_table->entries[i].locker_pid)
!= mypid<o:p></o:p></span></p>
<p class="MsoListParagraph"
style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0
level1 lfo4">
<!--[if !supportLists]--><span lang="EN-US"><span
style="mso-list:Ignore">-<span style="font:7.0pt
"Times New Roman"">
</span></span></span><!--[endif]--><span lang="EN-US">lock(&_tm_table->entries[i].mutex)<o:p></o:p></span></p>
<p class="MsoListParagraph"
style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0
level1 lfo4">
<!--[if !supportLists]--><span lang="EN-US"><span
style="mso-list:Ignore">-<span style="font:7.0pt
"Times New Roman"">
</span></span></span><!--[endif]--><span lang="EN-US">atomic_set(&_tm_table->entries[i].locker_pid,
mypid)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</blockquote>
<p>Not my code, but I would say it is safe, because the only race
condition you could possibly encounter where it would make a
difference is when atomic_get(&locker_pid) returns a value
other than mypid (true condition) and is then subsequently set to
mypid by a different thread before the mutex can be acquired
(flipping the condition to false), which cannot happen because all
threads have different PIDs.</p>
<p>Cheers<br>
</p>
</body>
</html>