<html xmlns:v="urn:schemas-microsoft-com:vml" 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)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 5 4 2 2 2 2 2 4;}
@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;
        color:windowtext;}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:24.0pt;
        font-family:"Calibri",sans-serif;
        color:black;
        font-weight:bold;}
h2
        {mso-style-priority:9;
        mso-style-link:"Heading 2 Char";
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:18.0pt;
        font-family:"Calibri",sans-serif;
        color:black;
        font-weight:bold;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Calibri",sans-serif;
        color:black;
        font-weight:bold;}
span.Heading2Char
        {mso-style-name:"Heading 2 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 2";
        font-family:"Calibri",sans-serif;
        color:black;
        font-weight:bold;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";
        color:black;}
.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 Juan,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> Hi Jaromir, hi all,</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> This is a most impressive work!</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Many thanks for your encouragement - I'm really glad you like it :)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> It made me remember this talk given by Martin McClure in Smalltalks 2019: https://www.youtube.com/watch?v=AvM5YrjK9AE . At minute 22:00, Martin states the behavior he expects from #terminate, and shows a test. I tried his test in Cuis,
 and sometimes (but not always) it failed. Jaromir, with your code, Martin's test now pass! In addition, I ran the existing Process tests, and none is made to fail.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Very interesting: I haven't touched the part for releasing critical sections (I thought it was an independent part I wanted to revisit later) but I'm relieved to hear it works properly with the proposed changes :) 
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In the talk Martin McClure also mentioned #valueUninterruptably. I've noticed Cuis doesn't implement it but I think with the suggested #terminate it could be implemented safely (fingers crossed).
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">BlockClosure >> valueUninterruptably</p>
<p class="MsoNormal">               ^ self ifCurtailed: [^ self]</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">At the moment however, Squeak and Pharo suffer a horrible damage to the image if you try:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">               [ self error ] valueUninterruptably</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">and later e.g.:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">               Semaphore new waitTimeoutMSecs: 50</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The worst part is the user won't notice anything and a simple code will run as if nothing happened - until an error or a crash happens. One of only a few ways to see something's off is e.g. Squeak's `Processor activeProcess = Project current
 uiProcess` which all of a sudden answers false (!)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But that's just Squeak/Pharo; Cuis is not affected as badly because it doesn't use the `effectiveProcess` mechanism.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Martin McClure also mentioned #valueUnpreemptively; funny thing is it doesn't work as designed because there's a bug in Process>>#priority which will leave the elevated process run at highest priority until it reaches a suspension point
 instead of bumping the priority back lower before returning from #valueUnpreemptively. It's discussed in this thread: http://forum.world.st/The-Inbox-Kernel-jar-1368-mcz-tp5126894p5126982.html . The conclusion is a new primitive for #priority is needed.
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> I also tried all your tests and examples. They cover a really broad and exhaustive set of scenarios! A few comments:</p>
<p class="MsoNormal">> - Many examples don't work in Cuis, because we made #fork answer nil (and not the forked process). The reason for this is explained in the comment in #fork. The pattern is instead of "p := [stuff] fork." do "p := [stuff] newProcess. p
 resume." With this change, all the examples work as expected.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Oops, apologies, I noticed the fork pattern (very reasonable), I modified my #fork to return the process to avoid the need to modify all the examples I created for Squeak :) Same for 'self error' unfortunately - for Cuis
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">               self error </p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">in the examples has to change to: </p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">               self error: 'unwind error'</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">sorry... </p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> - The notes for a few examples speak of crashes in Cuis. I pushed some fixes a few days ago, and now cmd-. works as expected. The examples behave the same as in Squeak. Please pull your repos.</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I will, thanks!</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> Additionally, this remark of you (Jaromir) I don't understand:</p>
<p class="MsoNormal">> /////</p>
<p class="MsoNormal">> ad 1) The #isTerminated condition `suspendedContext pc > suspendedContext startpc` is always met after executing the first instruction of the bottom context – generally not a sign of a terminated process.</p>
<p class="MsoNormal">> \\\\\\</p>
<p class="MsoNormal">> I don't see that condition neither in Squeak (#19435) nor Cuis (#4567).</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My bad explaining; I was talking about #isTerminated implementation in Cuis (and Pharo) using this old condition - on the last line of:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Process >> isTerminated</p>
<p class="MsoNormal">               "Answer true if terminated, i.e. can never be resumed again, because have nothing to run."</p>
<p class="MsoNormal">               self isRunning ifTrue: [^ false].</p>
<p class="MsoNormal">               ^suspendedContext isNil</p>
<p class="MsoNormal">                              or: [ suspendedContext pc isNil</p>
<p class="MsoNormal">                                             or: ["If the suspendedContext is the bottomContext it is the block in Process>>newProcess.</p>
<p class="MsoNormal">                                                            If so, and the pc is greater than the startpc, the bock has alrteady sent and returned</p>
<p class="MsoNormal">                                                            from value and there is nothing more to do."</p>
<p class="MsoNormal">                                                            suspendedContext isBottomContext</p>
<p class="MsoNormal">                                                                           and: [</p>
<p class="MsoNormal">                                                                                          suspendedContext pc > suspendedContext startpc]]]</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Squeak improved this condition a while ago but it's still insufficient :) It's discussed here: http://forum.world.st/The-Inbox-Kernel-jar-1376-mcz-tp5127335p5127341.html</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> In any case, I think this is a great contribution, It perfectly fixes a lot of broken behavior, and doesn't seem to bring problems. I'm all for integrating it.</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> Jaromir, do you intend to turn the rest of your examples into tests? I think we should also do that, so we integrate all your experiments and what you learnt.</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'd love to but I realized I don't know how to build tests involving raising errors and pressing Abandon on the Debugger :D If you could point me in the right direction it'd save me a lot of trying :)
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks a lot for all your comments. I'm happy you like the suggestion and would be delighted to see it integrated.
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> Thanks!</p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></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:juan@jvuletich.org">Juan Vuletich</a><br>
<b>Sent: </b>Tuesday, April 13, 2021 20:45<br>
<b>To: </b><a href="mailto:cuis-dev@lists.cuis.st">Discussion of Cuis Smalltalk</a><br>
<b>Cc: </b><a href="mailto:hernan.wilkinson@10pines.com">Hernan Wilkinson</a>; <a href="mailto:mail@jaromir.net">
Jaromir Matas</a><br>
<b>Subject: </b>Re: [Cuis-dev] Unwind mechanism during termination is broken and inconsistent</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:black">Hi Jaromir, hi all,<br>
<br>
This is a most impressive work!<br>
<br>
It made me remember this talk given by Martin McClure in Smalltalks 2019: <a href="https://www.youtube.com/watch?v=AvM5YrjK9AE">
https://www.youtube.com/watch?v=AvM5YrjK9AE</a> . At minute 22:00, Martin states the behavior he expects from #terminate, and shows a test. I tried his test in Cuis, and sometimes (but not always) it failed. Jaromir, with your code, Martin's test now pass!
 In addition, I ran the existing Process tests, and none is made to fail.<br>
<br>
I also tried all your tests and examples. They cover a really broad and exhaustive set of scenarios! A few comments:<br>
- Many examples don't work in Cuis, because we made #fork answer nil (and not the forked process). The reason for this is explained in the comment in #fork. The pattern is instead of "p := [stuff] fork." do "p := [stuff] newProcess. p resume." With this change,
 all the examples work as expected.<br>
- The notes for a few examples speak of crashes in Cuis. I pushed some fixes a few days ago, and now cmd-. works as expected. The examples behave the same as in Squeak. Please pull your repos.<br>
<br>
Additionally, this remark of you (Jaromir) I don't understand:<br>
/////<br>
ad 1) The #isTerminated condition `suspendedContext pc > suspendedContext startpc` is always met after executing the first instruction of the bottom context – generally not a sign of a terminated process.<br>
\\\\\\<br>
I don't see that condition neither in Squeak (#19435) nor Cuis (#4567).<br>
<br>
In any case, I think this is a great contribution, It perfectly fixes a lot of broken behavior, and doesn't seem to bring problems. I'm all for integrating it.<br>
<br>
Jaromir, do you intend to turn the rest of your examples into tests? I think we should also do that, so we integrate all your experiments and what you learnt.<br>
<br>
Thanks!<br>
<br>
<o:p></o:p></span></p>
<pre>-- </pre>
<pre>Juan Vuletich</pre>
<pre><a href="http://www.cuis-smalltalk.org">www.cuis-smalltalk.org</a></pre>
<pre><a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a></pre>
<pre><a href="https://github.com/jvuletich">https://github.com/jvuletich</a></pre>
<pre><a href="https://www.linkedin.com/in/juan-vuletich-75611b3">https://www.linkedin.com/in/juan-vuletich-75611b3</a></pre>
<pre>@JuanVuletich</pre>
<p class="MsoNormal"><span style="color:black"><br>
<br>
On 4/13/2021 6:02 AM, Jaromir Matas via Cuis-dev wrote: <o:p></o:p></span></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span style="color:black">Hi Hernan, hi all,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">I'm enclosing a slightly improved version of #terminate along with a few semantic tests covering basic nested unwind scenarios (terminating an active, suspended, blocked and ready processes in nested unwind blocks).
 More tests can be based on examples in the enclosed collection - for scenarios involving non-local returns and errors during termination and especially their combinations. A few examples explore resiliency of the code exposed to pathologic situations (nested
 termination or errors).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thanks again for your time. I look forward to your response.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">best,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Jaromir<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<div style="border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:rgb(225,
          225, 225) -moz-use-text-color -moz-use-text-color">
<p class="MsoNormal"><b><span style="color:black">From: </span></b><span style="color:black"><a href="mailto:cuis-dev@lists.cuis.st">Jaromir Matas via Cuis-dev</a><br>
<b>Sent: </b>Sunday, April 11, 2021 10:51<br>
<b>To: </b><a href="mailto:hernan.wilkinson@10pines.com">Hernan Wilkinson</a>; <a href="mailto:cuis-dev@lists.cuis.st">
Discussion of Cuis Smalltalk</a><br>
<b>Cc: </b><a href="mailto:mail@jaromir.net">Jaromir Matas</a><br>
<b>Subject: </b>Re: [Cuis-dev] Unwind mechanism during termination is broken and inconsistent<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Hi Hernan,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thank you very much for your immediate response.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">> Hi Jaromir,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  thank you for sharing this with us! It looks very interesting.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  As you can imagine a change of this magnitude and impact has to be analyzed in detail and tested rigorously, and that will take time.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Oh absolutely, I'm aware of that and wouldn't expect anything less :)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  It would help us deeply if there are tests that reproduce the errors, do you have them?
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Yes, I have a set of Squeak tests I'm planning to extend and make presentable ASAP. I'll "translate" them to Cuis too.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  If not, could you write them? I know it is a difficult problem to test but if we could have automated tests for this it would help a lot.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  Also, it would help to know how you tested it.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">That's important: I tested solely for 'correct' semantics in a series of simple scenarios I'll send you.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  For example, have you tried in stress conditions?
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Nope, I'm not that experienced unfortunately :)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  for example with an app that uses many processes (ie. seaside or any web framework). Please, do not take this question as disrespectful, but again,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  it is a change with a big impact and we need to be sure it will keep the current behavior (but the bugs of course) and it will not introduce new bugs.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  I'm also wondering if there could be systems that are implemented as these bugs you mention were "features" ...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">That's an interesting question. I realized the sooner bugs this deep in the system are fixed the less chance someone learns to 'live' with them, crippling their code, or even uses them as 'features'. I just hope
 it's not the case. How would we know? Well... actually here's one: while testing it on Pharo I found two tests that sort of 'legitimize' or use the Unwind error (bug) to achieve certain behavior... (if I interpret the tests correctly).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thanks again for your questions!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">Jaromir<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  Thanks!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black">>  Hernan.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<div style="border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:rgb(225,
          225, 225) -moz-use-text-color -moz-use-text-color">
<p class="MsoNormal"><b><span style="color:black">From: </span></b><span style="color:black"><a href="mailto:hernan.wilkinson@10pines.com">Hernan Wilkinson</a><br>
<b>Sent: </b>Sunday, April 11, 2021 1:47<br>
<b>To: </b><a href="mailto:cuis-dev@lists.cuis.st">Discussion of Cuis Smalltalk</a><br>
<b>Cc: </b><a href="mailto:mail@jaromir.net">Jaromir Matas</a><br>
<b>Subject: </b>Re: [Cuis-dev] Unwind mechanism during termination is broken and inconsistent<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:black">Hi Jaromir,<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:black"> thank you for sharing this with us! It looks very interesting.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> As you can imagine a change of this magnitude and impact has to be analyzed in detail and tested rigorously, and that will take time. (Sadly Juan and me are really busy at this time so it will even take more time
 :-) )<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> It would help us deeply if there are tests that reproduce the errors, do you have them? If not, could you write them? I know it is a difficult problem to test but if we could have automated tests for this it would
 help a lot. <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> Also, it would help to know how you tested it. For example, have you tried in stress conditions? for example with an app that uses many processes (ie. seaside or any web framework). Please, do not take this question
 as disrespectful, but again, it is a change with a big impact and we need to be sure it will keep the current behavior (but the bugs of course) and it will not introduce new bugs.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> I'm also wondering if there could be systems that are implemented as these bugs you mention were "features" ...<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> Thanks!<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> Hernan.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
<div>
<div>
<p class="MsoNormal"><span style="color:black">On Sat, Apr 10, 2021 at 4:20 PM Jaromir Matas via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<o:p></o:p></span></p>
</div>
<blockquote style="border:none;border-left:solid windowtext 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Hi All,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">I'd like to present to you a rewrite of #terminate and #isTerminated that fixes a few bugs and inconsistencies in process termination. I hoped it might interest you.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">I'm a Smalltalk enthusiast with education background in math/CS. I've been experimenting with processes in Squeak lately and discovered a few bugs (or at least inconsistencies) in process
 termination and would like to offer and discuss a solution for Cuis.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">The bugs are not unique to Cuis; Squeak/Pharo inherited them too and to a degree even Visual Works and VA are affected. The proposal presented here doesn't copy any VW or VA solution
 but rather implements a different approach :)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Before boring you to death I'll list the bugs:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">1. #isTerminated falsely reports almost any bottom context as terminated<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">2. an active process termination bug causes an image freeze
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">3. a <i>
nested</i> unwind bug: ensure blocks may get skipped during unwind<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">4. a failure to complete
<i>nested</i> unwind blocks halfway thru execution <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">5. a failure to correctly execute a non-local return or an error in an unwind block
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">6. inconsistent semantics of protected blocks unwind during active vs. suspended process termination<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">The current implementation of #terminate uses three different approaches to terminate a process:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">- the active process is terminated via a 'standard' unwind algorithm used in context #unwindTo: or #resume:,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">- a suspended process termination attempts completing unwind blocks halfway through their execution first using #runUntilErrorOrReturnFrom:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">- and after that the termination continues unwinding the remaining unwind blocks using the simulation algorithm of #popTo:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">This approach
<i>looks</i> inconsistent and indeed leads to inconsistencies, undesirable behavior and an instability mentioned above.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">The Idea: In my view the easiest and most consistent solution is to simply extend the existing mechanism for completing halfway-through unwind blocks and let it deal with
<b>all</b> unwind blocks. To make this approach applicable to terminating the active process, we suspend it first and then terminate it as a suspended process.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">A commented code is enclosed.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">I know it's pretty difficult to get a feedback on an ancient code; I'll be all the more grateful for your inputs.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Best regards,<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Jaromir<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">PS:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Note the change in newProcess - `Processor activeProcess terminate` is replaced by `Processor activeProcess suspend` because there's no need for `terminate` at the bottom context ("terminate
 = unwind + suspend") and because it would lead to an infinite loop combined with my proposed changes to #terminate.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">PPS:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">More on the bugs:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">ad 1) The #isTerminated condition `suspendedContext pc > suspendedContext startpc` is always met after executing the first instruction of the bottom context – generally not a sign of
 a terminated process.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">ad 2) Explained in [1]. Concerns e.g. examples like
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">              [ [ Processor activeProcess terminate ] ensure: [ Processor activeProcess terminate ] ] fork.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">ad 3-4) Explained in detail in [2].<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">One example to illustrate the bug:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">| p |<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">p := [<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">              [<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                           [ ] ensure: [<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                                         [ ] ensure: [<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                                                       Processor activeProcess suspend.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                                                       Transcript show: 'x1'].
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                                         Transcript show: 'x2']<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">              ] ensure: [<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">                           Transcript show: 'x3']<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">] newProcess.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">p resume.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">Processor yield.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">p terminate<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">===> x1<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">The unwind procedure prints just x1 and skips not only x2 but x3 as well ! You'd like to see them all.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">ad 5) This happens in cases like (better save your image before trying this):<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">              [self error: 'e1'] ensure: [^2]        "discovered by Christoph Thiede"<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">and<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">              [self error: 'e1'] ensure: [self error: 'e2']<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">These are generally the types of situations causing the Unwind errors. The root cause is that the unwinding is done via simulation (#popTo) rather than 'directly'; the problem is during
 the simulated execution of unwind blocks a non-local return forwards the execution into a wrong stack - resulting in the Unwind errors.
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">ad 6) I just prefer a unified approach... unless I somehow overlooked a reason for two different approaches (I hope not).<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">[1] <a href="http://forum.world.st/A-bug-in-active-process-termination-crashing-image-td5128186.html" target="_blank">
http://forum.world.st/A-bug-in-active-process-termination-crashing-image-td5128186.html</a><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">[2] <a href="http://forum.world.st/Another-bug-in-Process-gt-gt-terminate-in-unwinding-contexts-td5128171.html#a5128178" target="_blank">
http://forum.world.st/Another-bug-in-Process-gt-gt-terminate-in-unwinding-contexts-td5128171.html#a5128178</a><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black"> <o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:45.6pt"><span style="color:black">-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><o:p></o:p></span></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:black"><br clear="all">
<o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span style="color:black"> <o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:black">-- <o:p></o:p></span></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><a href="https://10pines.com/" target="_blank"><span style="font-size:13.5pt;font-family:"Helvetica",sans-serif;text-decoration:none"><img border="0" width="108" height="34" style="width:1.125in;height:.35in" id="_x0000_i1025" src="https://10pines.github.io/email-signature/10pines-firma@2x.png"></span></a><span style="color:black"><o:p></o:p></span></p>
<h1 style="margin:0in"><span style="font-size:10.5pt">Hernán Wilkinson</span><o:p></o:p></h1>
<h2 style="margin-bottom:12.0pt"><span style="font-size:10.5pt;color:#646464">Software Developer, Teacher & Coach</span><o:p></o:p></h2>
<p style="margin:0in"><span style="font-size:9.0pt">Alem 896, Floor 6, Buenos Aires, Argentina</span></p>
<p style="margin:0in"><span style="font-size:9.0pt">+54 11 6091 3125</span></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p style="margin:0in"><span style="font-size:9.0pt;color:#646464">@HernanWilkinson</span></p>
</blockquote>
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:5.0pt;margin-left:.5in">
<span style="color:black"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
</div>
</body>
</html>