<!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 8/1/2022 9:38 AM, Jaromir Matas via Cuis-dev wrote:
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.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)">
<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;}
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;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
{mso-style-priority:1;
margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
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>
<div class="WordSection1">
<p class="MsoNormal">Hi Juan,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In our previous discussion we discussed a
few examples:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">[ 10000 factorial. 5 seconds asDelay wait ]
repeat</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This one represents a situation where the
UI is blocked and we (mostly you indeed) modified the code to
create a new UI to open the debugger for the [1/0] process
request while the old UI is idly waiting.</p>
</div>
</blockquote>
<br>
Right.<br>
<br>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"><o:p> <br>
</o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">[ 10000 factorial. Processor yield ] repeat</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This one represents a different situation
where, again, the [1/0] process starts executing but the debug
request gets stuck (deferred) in the UI process because the UI
process is "busy" executing its Workspace task.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">We concluded that this looks like a more
complex scenario than the "blocked UI" scenario presented
above.
</p>
</div>
</blockquote>
<br>
My thought was that 'you asked your UI process to be busy, so you
don't get UI'.<br>
<br>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">The more I think about it the more I lean
toward treating both scenarios equally, i.e. create a new UI
in both scenarios, in other words create a new UI for every
debug request.</p>
</div>
</blockquote>
<br>
Ok. Yes, this was enough to convince me. The debugger is a special
tool. It is reasonable to always start a fresh UI process for it. In
OS level debuggers, common practice is to start a debugger (in its
own OS process) and then 'attach' it to the process being debugged.
Makes sense.<br>
<br>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">The main difference between the two
scenarios is *where* - at which queue the UI process is
waiting when the debug request occurs: whether on a Semaphore
or on a Processor's ready list (apologies for stating the
obvious: the UI process is waiting somewhere by definition
when a debug request from another process occurs). I'm aware
my experience is very limited but I can't come up with any
argument why *not* treat them equally :) Treating them equally
looks to me cleaner, simpler and may even allow some more
simplifications.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here's my suggestion (as usual I'm not sure
I'm placing my modification at the most appropriate location
but you get the idea):</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">newUIProcessIfNeeded</p>
<p class="MsoNormal"> "If the system needs a
UIProcess (we know because UIProcess is not nil),</p>
<p class="MsoNormal"> then ensure that the
UIProcess is ready to run, in order to have a responsive UI.</p>
<p class="MsoNormal"> If we needed to create a
new UI process, answer the old one, as it is most likely the</p>
<p class="MsoNormal"> process the user is
interested in debugging. See senders."</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> UIProcess ifNotNil: [
:oldUIProcess |</p>
<p class="MsoNormal"> self
spawnNewMorphicProcessFor: UI.</p>
<p class="MsoNormal">
^oldUIProcess ].</p>
<p class="MsoNormal"> ^nil</p>
</div>
</blockquote>
<br>
It is reasonable to try that as an experiment, but if you follow the
several chains of senders to #spawnNewMorphicProcessFor: , you'll
see this got to dirty, because of making many small, unrelated
changes over the years. In the current shape of the code it is hard
to guarantee that all requests to open a debugger behave in a
consistent way.<br>
<br>
So, I spent a couple of days refactoring and cleaning it. The result
is 18 cleanup & refactor changesets, that shouldn change
behavior much, and one single change that essentially does what you
suggest, but it is now much easier to follow. I pushed this to
github yesterday. The change sets that starts a new process for
every debugger (except when the user debugs an expression) is in
change set #5434.<br>
<br>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">With this change the following examples
work:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">Processor yield.</p>
<p class="MsoNormal">[ 10000 factorial ] repeat</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">[ 10000 factorial. Processor yield ] repeat</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Surprisingly, even the following example
works, i.e. opens a debugger instead of getting stuck, but in
this case it is also thanks to some unrelated interrupts at
play preempting the old UI and allowing the new UI run..</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1/0] fork.</p>
<p class="MsoNormal">[ 10 factorial ] repeat</p>
</div>
</blockquote>
<o:p></o:p> <br>
Yep. All these work as expected now. It is interesting to open a
ProcessBrowser, though, and see how the 'former UI process' is still
busy computing factorials!<br>
<o:p><br>
</o:p>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">An interesting observation:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The suggested modification works under the
assumption that </p>
<p class="MsoNormal"> Smalltalk
processPreemptionYields</p>
<p class="MsoNormal">returns true, which is Cuis's default
(unlike Squeak's); once you change it to false, i.e. once you
change the order ready processes are placed in the Processor's
ready queue, it won't work; the preemption mode is critical in
this case so I'll have to figure out how to make this work for
Squeak :D Or better yet how to make it independent of the
processPreemptionYields setting.</p>
</div>
</blockquote>
<o:p></o:p> <br>
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.<br>
<br>
<o:p></o:p>
<blockquote
cite="mid:BL0PR03MB406578B373B738CD7FAF7EF9EE9A9@BL0PR03MB4065.namprd03.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">To conclude: if you won't find some fatal
flaw with this approach it seems to me it allows to run code
fragments in the UI as usual but once a more complex scenario
occurs, like a parallel process requesting a debugger, a new
UI is created to take over so that the old UI process can
continue executing its unfinished task without the need to act
as a UI any longer (and will automatically terminate once it
finishes its current cycle).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Again, I'll very much appreciate any
comments or suggestions you might have; thanks for your time
and patience reading such long message :)</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Best,</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>
</div>
</blockquote>
<br>
Thanks a lot for trying all these things, suggesting course of
action, and especially thank you for the great discussion. It is
always great to be able to talk about these issues. And Cuis is
always improving this way!<br>
<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>