<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Jaromir,<br>
<br>
On 4/14/2021 5:37 AM, Jaromir Matas via Cuis-dev wrote:
<blockquote
cite="mid:BN7PR08MB3842F3849FF9C29E23161C46EE4E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<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;}
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;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
<div class="WordSection1">
<p class="MsoNormal">Hi Juan, hi all,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m enclosing an amended list of examples
with fixed #fork and ‘self error’ patterns so that you can use
them right away.</p>
</div>
</blockquote>
<br>
Thanks!<br>
<br>
<blockquote
cite="mid:BN7PR08MB3842F3849FF9C29E23161C46EE4E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<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,
<o:p></o:p></p>
<p class="MsoNormal">> and now cmd-. works as expected. The
examples behave the same as in Squeak.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Yes, it’s perfect :) I removed the crash
notes from the example list.</p>
</div>
</blockquote>
<br>
Thanks.<br>
<br>
<blockquote
cite="mid:BN7PR08MB3842F3849FF9C29E23161C46EE4E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">A little correction: I haven’t realized
Martin McClure was talking from a Visual Works position - they
have different semantics of #valueUninterruptably (at least in
8.3 from 2017, using a semaphore).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The Squeak semantics of
#valueUninterruptably is “don’t let anything kill me” (using a
non-local return in the unwind block).</p>
</div>
</blockquote>
<br>
Yes. In Cuis we don't have that method. I don't quite see the use
case for it. In any case, I think I prefer Martin and Esteban
Maringolo's:<br>
<br>
valueEnsured<br>
"Protect against process termination.<br>
Suggested by Esteban Maringolo at Martin McClure's 'Threads,
Critical Sections, and Termination' (Smalltalks 2019 conference)"<br>
[] ensure: self<br>
<br>
<blockquote
cite="mid:BN7PR08MB3842F3849FF9C29E23161C46EE4E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">Best regards,</p>
<p class="MsoNormal">Jaromir</p>
</div>
</blockquote>
<br>
Finally, I took a look at your first example requiring user
operation of the debugger. The debugger tells the suspended process
#terminate (on debugger close) or #resume (on debugger proceed). So
this example of yours:<br>
<br>
<br>
[<br>
[ ] ensure: [<br>
[self error: 'unwind test'] ensure: [<br>
Transcript show: 'x1']. <br>
Transcript show: 'x2']<br>
] ensure: [<br>
Transcript show: 'x3'].<br>
Transcript show: 'x4'<br>
<br>
ended up looking:<br>
<br>
p := [<br>
[<br>
[ ] ensure: [<br>
[p suspend] ensure: [<br>
Transcript show: 'x1']. <br>
Transcript show: 'x2']<br>
] ensure: [<br>
Transcript show: 'x3'].<br>
Transcript show: 'x4'<br>
] newProcess.<br>
p resume.<br>
Processor yield.<br>
"p terminate." "Equivalent to closing the debugger"<br>
"p resume." "Equivalent to [proceed] in the debugger"<br>
<br>
which is essentially the same as the first example in your txt. So,
if you are willing to turn all these examples into tests, I think
that using the first version, that doesn't activate the debugger is
ok. Maybe adding the #resume case (to assert that all the prints are
run), and maybe adding the non-local return variant is worth doing,
though.<br>
<br>
WRT the `suspendedContext pc > suspendedContext startpc`
condition in #terminate, you were completely right, and I got
confused. Apologies. Still, it seems that that code was originally
written knowing the specific details in #newProcess. In any case
your version of #terminate is a cleaner alternative.<br>
<br>
Thanks again for your hard work!<br>
<br>
Cheers,<br>
<br>
<blockquote
cite="mid:BN7PR08MB3842F3849FF9C29E23161C46EE4E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border-right: medium none; border-width: 1pt medium
medium; border-style: solid none none; border-color: rgb(225,
225, 225) -moz-use-text-color -moz-use-text-color; padding:
3pt 0in 0in;">
<p class="MsoNormal" style="border: medium none; padding:
0in;"><b>From: </b><a moz-do-not-send="true"
href="mailto:cuis-dev@lists.cuis.st">Jaromir Matas via
Cuis-dev</a><br>
<b>Sent: </b>Wednesday, April 14, 2021 0:20<br>
<b>To: </b><a moz-do-not-send="true"
href="mailto:juan@jvuletich.org">Juan Vuletich</a>; <a
moz-do-not-send="true"
href="mailto:cuis-dev@lists.cuis.st">
Discussion of Cuis Smalltalk</a><br>
<b>Cc: </b><a moz-do-not-send="true"
href="mailto:mail@jaromir.net">Jaromir Matas</a>; <a
moz-do-not-send="true"
href="mailto:hernan.wilkinson@10pines.com">
Hernan Wilkinson</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">Hi Juan,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> Hi Jaromir, hi all,<o:p></o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal">> This is a most impressive work!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Many thanks for your encouragement - I'm
really glad you like it :)<o:p></o:p></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:
<a class="moz-txt-link-freetext" 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.<o:p></o:p></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 :)
<o:p></o:p></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).
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">BlockClosure >> valueUninterruptably<o:p></o:p></p>
<p class="MsoNormal"> ^ self ifCurtailed: [^ self]<o:p></o:p></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:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> [ self error ]
valueUninterruptably<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">and later e.g.:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> Semaphore new
waitTimeoutMSecs: 50<o:p></o:p></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 (!)<o:p></o:p></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.<o:p></o:p></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:
<a class="moz-txt-link-freetext" href="http://forum.world.st/The-Inbox-Kernel-jar-1368-mcz-tp5126894p5126982.html">http://forum.world.st/The-Inbox-Kernel-jar-1368-mcz-tp5126894p5126982.html</a>
. The conclusion is a new primitive for #priority is needed.
<o:p></o:p></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:<o:p></o:p></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.<o:p></o:p></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
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> self error <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">in the examples has to change to: <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> self error: 'unwind error'<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">sorry... <o:p></o:p></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.<o:p></o:p></p>
<p class="MsoNormal">><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I will, thanks!<o:p></o:p></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:<o:p></o:p></p>
<p class="MsoNormal">> /////<o:p></o:p></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.<o:p></o:p></p>
<p class="MsoNormal">> \\\\\\<o:p></o:p></p>
<p class="MsoNormal">> I don't see that condition neither in
Squeak (#19435) nor Cuis (#4567).<o:p></o:p></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:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Process >> isTerminated<o:p></o:p></p>
<p class="MsoNormal"> "Answer true if terminated,
i.e. can never be resumed again, because have nothing to run."<o:p></o:p></p>
<p class="MsoNormal"> self isRunning ifTrue: [^
false].<o:p></o:p></p>
<p class="MsoNormal"> ^suspendedContext isNil<o:p></o:p></p>
<p class="MsoNormal"> or: [
suspendedContext pc isNil<o:p></o:p></p>
<p class="MsoNormal">
or: ["If the suspendedContext is the bottomContext it is the
block in Process>>newProcess.<o:p></o:p></p>
<p class="MsoNormal">
If so, and the pc is greater than
the startpc, the bock has alrteady sent and returned<o:p></o:p></p>
<p class="MsoNormal">
from value and there is nothing
more to do."<o:p></o:p></p>
<p class="MsoNormal">
suspendedContext isBottomContext<o:p></o:p></p>
<p class="MsoNormal">
and: [<o:p></o:p></p>
<p class="MsoNormal">
suspendedContext pc > suspendedContext startpc]]]<o:p></o:p></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:
<a class="moz-txt-link-freetext" href="http://forum.world.st/The-Inbox-Kernel-jar-1376-mcz-tp5127335p5127341.html">http://forum.world.st/The-Inbox-Kernel-jar-1376-mcz-tp5127335p5127341.html</a><o:p></o:p></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.<o:p></o:p></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.<o:p></o:p></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 :)
<o:p></o:p></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.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> Thanks!<o:p></o:p></p>
<p class="MsoNormal">><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"><o:p> </o:p></p>
<p class="MsoNormal">Jaromir<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color: black;"></span></p>
</div>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Juan Vuletich
<a class="moz-txt-link-abbreviated" href="http://www.cuis-smalltalk.org">www.cuis-smalltalk.org</a>
<a class="moz-txt-link-freetext" href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a class="moz-txt-link-freetext" href="https://github.com/jvuletich">https://github.com/jvuletich</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/juan-vuletich-75611b3">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</body>
</html>