<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Jaromir,<br>
<br>
On 8/10/2022 9:24 AM, Jaromir Matas via Cuis-dev wrote:
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<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;}
@font-face
{font-family:"Calibri Light";
panose-1:2 15 3 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;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
{mso-style-priority:1;
margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.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>
<div class="WordSection1">
<p class="MsoNormal">Hi Juan,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I very much like your simplifying the code
opening a debugger :)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'm still just skimming the surface of the
UI implementation but I'd like to ask a few questions:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(1) why is there Object >>
#runningWorld </p>
<p class="MsoNormal">- wouldn't sending `UISupervisor
runningWorld` instead of `true runningWorld` be sufficient
e.g. in Debugger >>
#openWindowLabel:usePreDebugWindow:preDebugMessage:?</p>
</div>
</blockquote>
<o:p><br>
Yes, of course. The implementation in Object is just to avoid
creating references to UISupervisor all over the place, in case
some day we want to replace it with something else. It is just
that I wasn't so sure about UISupervisor when I created it. Not a
big deal, IMO.<br>
<br>
</o:p>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">(2) Why not define UISupervisor >>
runningWorld via #animatedUIOf: to avoid code duplicity?</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">UISupervisor >> runningWorld</p>
<p class="MsoNormal"> "</p>
<p class="MsoNormal"> UISupervisor runningWorld</p>
<p class="MsoNormal"> [ UISupervisor runningWorld
print ] fork</p>
<p class="MsoNormal"> "</p>
<p class="MsoNormal"> ^self animatedUIOf:
Processor activeProcess</p>
</div>
</blockquote>
<br>
Yeah. Good idea. Just post the .cs, so it has your initials :)<br>
<br>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"></p>
<p class="MsoNormal">(3) I understand your intention when you
lowered the former UI process's priority in
#spawnNewMorphicProcessFor: by one; I believe it was in
response to this example:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">5 seconds asDelay wait.</p>
<p class="MsoNormal">self error: 'error'</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I've been wondering whether it's still
relevant after your most recent changes - and unfortunately it
seems that it is: changing the former UI process's priority
back to the active priority will cause redraw glitches (e.g.
Transcript background color in Dark mode won't display
properly). </p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">However, there seems to be a very similar
redraw blip *despite* the lower priority tweak when running
e.g.</p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">[1/0] fork</p>
<p class="MsoNormal">... the Transcript window won't get redrawn
correctly in the Dark mode: it won't change its background
color properly. It puzzles me why the Transcript window is the
only one affected.</p>
</div>
</blockquote>
<br>
The Transcript is special. It will do the same in any Theme,
although the difference may be less obvious. Try `1 to: 4 do: [ :i |
i print. 100000 factorial ]` in a Workspace. Do it with another
window partially covering the Transcript. The thing here is that the
Transcript gets immediate updates, without waiting for the next
Morphic cycle. This is extremely useful for debugging, and
especially for debugging Morphic itself. Browse a bit Transcript and
you'll see.<br>
<br>
The reason to lower the older Morphic priority is to guarantee a
responsive UI, a focus of yours in the last months. Besides, given
that (see below) in Cuis two processes of the same priority can
interrupt each other at any time, and given that Morphic is not
thread safe, then, as we want the old Morphic process to finish its
stuff (as many of your examples required), we need to make that with
a lower priority than the main UI process, to reduce the risk of the
old process breaking state needed by the new one.<br>
<br>
<o:p></o:p>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">What I'm trying to figure out is: if the
computation carried out by this former UI process involves
references to Processor activePriority the priority-lowering
tweak may change the semantics of a computation involving
forking processes at different relative priorities (in other
words changing the priority of the process in the middle of
the computation by an *unrelated* "outsider" process feels
dangerous); just a theoretical idea though, unfortunately I
don't have any practical example or any further suggestion;
I'll return to this later after some more educating myself :)</p>
</div>
</blockquote>
<o:p></o:p>
<o:p><br>
But it is not an *unrelated* process. It is the UISupervisor, who
created it in the first place, gave it the chore of running the
World, and is now replacing it with a new one.<br>
<br>
</o:p>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">About the processPreemptionYields flag:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">> I think it would be important to
understand why would someone want #processPreemptionYields =
false. Their reasons for requesting a process to never yield
to others of same priority (even if some higher process wakes
up in between) may also mean they don't want new UI processes
to be started so lightly.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here's Eliot's explanation why he chose
#processPreemptionYields = false over the previous
functionality:
<a class="moz-txt-link-freetext" href="https://forum.world.st/about-signal-tp5109735p5109862.html">https://forum.world.st/about-signal-tp5109735p5109862.html</a></p>
</div>
</blockquote>
<o:p><br>
I know. I've been here since before Squeak ran Morphic, and it was
MVC only. I understand MVC process scheduling in Smalltalk-80 and
its evolution through Morphic.<br>
<br>
#processPreemptionYields = false is the intended behavior in
Smalltalk-80. In Smalltalk-80 a process can only be preempted by
one of a higher priority. This means that no real access
protection is needed between processes of the same priority (given
that they only #yield at safe places). This is akin to Corroutines
(and #resumeNext semantics). But the original Squeak VM, when
resuming a high priority process, will put the active process at
the back of the process queue, possibly breaking older code. This
is the #processPreemptionYields = true behavior. Squeak needed
then to adapt to this behavior. Much later, Eliot added the
#processPeemptionYields = false to restore the original
Smalltalk-80 intended behavior, which could be safer for code
unaware of these issues.<br>
<br>
In Cuis, no assumption is made. The way to protect access to
Morphic state is to call #whenUIinSafeState: . So,
#processPreemptionYields can be set to true. I believe this is
what most people would expect in these days. The last mainstream
OS that switched from "cooperative multitasking" to "preemptive
multitasking" was MacOS about 20 years ago!<br>
<br>
</o:p>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">My understanding is he simply thinks
#processPreemptionYields = true produces an
inconsistent/erroneous behavior in the sense that unless a
process *explicitly* yields control it should stay in control
(unless preempted by a higher priority process in which case
it should get back control once the higher priority process
gives up control, i.e. stay at the front of the run queue).
</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In case of Squeak (which is on
#processPreemptionYields = false) each world cycle does
contain an explicit yield anyway so opening each debugger in a
new UI doesn't seem to clash with this stricter
cooperative-within-priorities scheduling approach imho :)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">A while ago I asked Marcel about the
preemption modes and the answer was (roughly) that
#processPreemptionYields = false offers more predictability
(understandably) plus something about thread-safe-ness of
Morphic structures (which is still way beyond my skills
level).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is there a reason why you'd prefer
#processPreemptionYields = true or is it just for historic
reasons? ("why fix something that works" type of situation? :)
)</p>
</div>
</blockquote>
<br>
Absolutely the contrary!<br>
<br>
#processPreemptionYields = false is to keep the Smalltalk-80
cooperative multitasking style that was widespread until mid 90's,
when Linux and Windows made the transition, followed a few years
later by MacOS. In Cuis we explicitly made the change to
#processPreemptionYields = true about a decade ago to be in line
with modern practice. In doing so, I needed to come up with
#whenUIinSafeState: and make sure that nothing broke. Another
situation where Cuis favors progress in spite of back compatibility.<br>
<br>
<blockquote
cite="mid:DM6PR03MB40732B44A83EDD5FBE034848EE659@DM6PR03MB4073.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks again very much for discussing these
issues!</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best regards,</p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNoSpacing"><span lang="CS">--</span></p>
<p class="MsoNoSpacing"><strong><span style="font-family:
"Calibri Light",sans-serif; color: rgb(51, 51,
51); font-weight: normal;">Jaromír Matas</span></strong><span
style="font-family: "Calibri Light",sans-serif;
color: rgb(85, 85, 85);"><o:p></o:p></span></p>
<p class="MsoNoSpacing"><span style="font-family: "Calibri
Light",sans-serif; color: rgb(46, 117, 182);"><a class="moz-txt-link-abbreviated" href="mailto:mail@jaromir.net">mail@jaromir.net</a></span></p>
<p class="MsoNormal"><o:p> </o:p><br>
</p>
</div>
</blockquote>
<br>
Cheers,<br>
<pre class="moz-signature" cols="72">--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich</pre>
</body>
</html>