<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Marcel,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The issue is fixed for #terminate by using #suspendAndReleaseCriticalSection and the corresponding tests are #testMutexInCriticalEnsureArgument and #testSemaInCriticalEnsureArgument; however, the issue still remains in #releaseCriticalSection:
 which is being used by #terminateAggressively which means if you run the same example but Abandon the debugger instead of terminating it the Mutex's owner won't get cleared which is the bug.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">To summarize the root cause: the code in #releaseCriticalSection: tries to deal with three possible implementations of #critical (see https://forum.world.st/Solving-termination-of-critical-sections-in-the-context-of-priority-inversion-was-SemaphoreTest-fail-tp5082184.html);
 eventually version V1 was adopted but the code dealing with V2 remained and left a hole causing V1 fail in the case showed by the example (below).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The fix was that I used only the relevant code from #releaseCriticalSection: in #suspendAndReleaseCriticalSection being used by #terminate.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The question remains what to do with #terminateAggressively (Abandon); I've just tried to simply replace #releaseCriticalSection: with #suspendAndReleaseCriticalSection but that doesn't seem to help and my original fix doesn't work for
 #terminateAggressively either which means there may be something else at play here.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:marcel.taeumel@hpi.de">Marcel Taeumel</a><br>
<b>Sent: </b>Thursday, July 7, 2022 15:00<br>
<b>To: </b><a href="mailto:squeak-dev@lists.squeakfoundation.org">squeak-dev</a><br>
<b>Subject: </b>Re: [squeak-dev] A bug in #releaseCriticalSection: preventing correct unwind (in rare situations)</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">Hi Jaromir --<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">What is the current status of this? :-)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">Best,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">Marcel<o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid windowtext 1.0pt;padding:0in 0in 0in 8.0pt;margin-left:0in;margin-top:15.0pt;margin-bottom:5.0pt">
<p style="margin-top:7.5pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:#AAAAAA">Am 21.12.2021 18:14:21 schrieb mail@jaromir.net <mail@jaromir.net>:<o:p></o:p></span></p>
</blockquote>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:12.0pt;margin-left:0in">
<span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black">Hi Eliot, all,
<br>
<br>
There's a bug, or rather an omission, in #releaseCriticalSection: causing the following examples unwind incorrectly:
<br>
<br>
Mutex new inspect critical: [self halt] <br>
<br>
If you run the example in a workspace, a debugger and an inspector opens - please watch Mutex's 'owner' variable; then step into a few times to get right before sending #primitiveExitCriticalSection and terminate the debugger (in the newest images please use
 debugger's window menu -> terminate process); and observe the owner won't get cleared and will remain blocking the Mutex. Same behavior for Semaphores:
<br>
<br>
Semaphore forMutualExclusion inspect critical: [self halt] <br>
<br>
Again, watch Semaphore's excessSignals variable in the Inspector, step into a few times until you stand before sending #signal - and terminate the debugged process (from the debuggers menu or from the Process Browser if you like) - the Semaphore won't recharge
 excessSignals back to 1. <br>
<br>
The root cause is #releaseCriticalSection: doesn't account for terminating in this particular position of the computation. It can be fixed e.g. by adding an additional condition ('progressedIntoEnsure') - try the examples with the enclosed changeset; both Mutexes
 and Semaphores work ok now. <br>
<br>
Best, <br>
<br>
~~~ <br>
^[^ Jaromir <br>
<br>
Sent from Squeak Inbox Talk <br>
["Process-releaseCriticalSection.st"] <o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>