<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=Windows-1252">
<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 Eliot, all,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm back to my original question what is the *<b>desirable</b>* semantics of #resume and #suspend for Squeak:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">We’ve discussed #suspend and you’ve implemented the very elegant backing of the blocked process before the send wait.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Now we have this unexpected #resume behavior plainly letting a process continue regardless of whether it’s being blocked.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ve checked VW and VA:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">VW’s #suspend removes the process from the conditional variable’s list and #resume fails an attempt to resume a blocked process. The examples below behave as expected.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">VA on the other hand treat blocked processes equally as suspended processes which seems to me as if they ignored/redefined the idea of conditional variables; i.e. suspending a blocked process is a no-op and resuming a blocked process simply
 removes it from the semaphore and puts it in the runnable list.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It seems to me Squeak sits inconsistently somewhere in-between. From #resume and #suspend comments being identical to VW’s I guess VW’s behavior was the original intention.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">best,</p>
<p class="MsoNormal">~~~</p>
<p class="MsoNormal">^[^    Jaromir</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:mail@jaromir.net">Jaromir Matas</a><br>
<b>Sent: </b>Thursday, January 13, 2022 19:29<br>
<b>To: </b><a href="mailto:vm-dev@lists.squeakfoundation.org">vm-dev@lists.squeakfoundation.org</a>;
<a href="mailto:eliot.miranda@gmail.com">Eliot Miranda</a><br>
<b>Subject: </b>Unexpected #resume behavior</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Hi Eliot, all,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm baffled by this example:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">p := [Semaphore new wait] fork.<o:p></o:p></p>
<p class="MsoNormal">Processor yield.<o:p></o:p></p>
<p class="MsoNormal">p resume explore<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I expected to get an error but the process just gets out of the semaphore and finishes happily.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">#resume comment says:<o:p></o:p></p>
<p class="MsoNormal">                Primitive. Allow the process that the receiver represents to continue. Put
<o:p></o:p></p>
<p class="MsoNormal">                 the receiver in line to become the activeProcess.  *Fail if the receiver is
<o:p></o:p></p>
<p class="MsoNormal">                 already waiting in a queue (in a Semaphore or ProcessScheduler)*.  Fail if<o:p></o:p></p>
<p class="MsoNormal">                the receiver's suspendedContext is not a context.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The following works as expected - p sits at the semaphore:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">p := [Semaphore new wait] fork.<o:p></o:p></p>
<p class="MsoNormal">Processor yield.<o:p></o:p></p>
<p class="MsoNormal">p explore<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This works as well (with the new VM) - p backs up and sits before the wait:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">p := [Semaphore new wait] fork.<o:p></o:p></p>
<p class="MsoNormal">Processor yield.<o:p></o:p></p>
<p class="MsoNormal">p suspend.<o:p></o:p></p>
<p class="MsoNormal">p explore<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And this works too indeed - p sits at the semaphore again after suspend.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">p := [Semaphore new wait] fork.<o:p></o:p></p>
<p class="MsoNormal">Processor yield.<o:p></o:p></p>
<p class="MsoNormal">p suspend.<o:p></o:p></p>
<p class="MsoNormal">p resume explore<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is this a bug? Or is the comment just outdated? <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I've been trying to figure out possible ways how to prevent resuming a process being terminated (other than setting its suspendedContext to nil) and this unexpected behavior gave me a real hard time :)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Many thanks for your help.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards,<o:p></o:p></p>
<p class="MsoNormal">Jaromir<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>