<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Marcel, Hi All,<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 25, 2021 at 3:26 AM Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div id="gmail-m_-4475141367309418__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0);text-align:left" dir="ltr">
                                        > <span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">It's simply not thread-safe.</span><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Hmm... in particular, there is a side effect (i.e. layout update) in the window's pluggable text morph. Even if #forceUpdate is false.</span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">In #endEntry, we could check for "Processor activeProcess == Project current uiProcess" to then use "Project current addDeferredUIMessage..." automatically.</span></div></div></blockquote><div><br></div><div class="gmail_default" style="font-size:small">That gave me a scare.  At first I thought that the effectiveProcess changes to ProcessorScheduler>>activeProcess could have made that expression no longer thread safe.  But it isn't anyway, and the above is very bad style.  Let me explain.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The suspension points in the VM are </div><div class="gmail_default" style="font-size:small">- the first bytecode of any non-quick method (following a primitive if it has one)</div><div class="gmail_default" style="font-size:small">- the first bytecode of any block</div><div class="gmail_default" style="font-size:small">- a backward branch</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In the JIT there are fewer suspension points:</div><div class="gmail_default" style="font-size:small">- the first bytecode of any method containing a send other than #== and/or #class (and given that ifNil:ifNotNil: is inlined into a send of #== and jumps, ifNil: sends don't count)</div><div class="gmail_default"><span style="color:rgb(0,0,0)">- the first bytecode of any<font face="arial, sans-serif"> block </font></span><span style="color:rgb(0,0,0)"><font face="arial, sans-serif">containing a send other than #== and/or #class</font></span></div><div class="gmail_default" style="color:rgb(0,0,0)"></div><div class="gmail_default"><font face="arial, sans-serif">- a backward branch</font></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">So given</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">ProcessorScheduler>>#activeProcess</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre"><span style="color:rgb(0,0,0)">        "suspension point here on an interpreter VM, and the first time in the JIT VM"</span></span></div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>^activeProcess effectiveProcess</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Process>>#effectiveProcess</div><div class="gmail_default" style="font-size:small">        "suspension point here on an interpreter VM, and the first time in the JIT VM"</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>^effectiveProcess ifNil: [self]</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Project class>>#current</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre"><span style="color:rgb(0,0,0)">        "suspension point here on an interpreter VM, and the first time in the JIT VM"</span></span></div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>^CurrentProject</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">MVCProject>>#uiProcess<br></div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-tab-span" style="white-space:pre"><span style="color:rgb(0,0,0)">        "suspension point here on an interpreter VM, and the first time in the JIT VM"</span></span></div><div class="gmail_default" style="font-size:small"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>^ world activeControllerProcess<br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">MorphicProject>>#uiProcess</div><div class="gmail_default" style="font-size:small"><div class="gmail_default" style="color:rgb(0,0,0)">        "no suspension point here on any VM obeying the blue-book spec"</div></div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>^uiProcess</div><div class="gmail_default"><font face="arial, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)">we can see that "Processor activeProcess == Project current uiProcess" is not thread-safe in the interpreter; there is a suspension point in Project current before </span><span style="color:rgb(0,0,0)">CurrentProject is returned (but not in the JIT); there is a suspension point in MVC in uiProcess.  There is a suspension point in </span><span style="color:rgb(0,0,0)">ProcessorScheduler>>#activeProcess before the send of </span><span style="color:rgb(0,0,0)">effectiveProcess to activeProcess, but since no data is fetched until the process resumes this is harmless.  However, were the expression written as "</span><span style="color:rgb(0,0,0)">Project current uiProcess == </span><span style="color:rgb(0,0,0)">Processor activeProcess" then this would no longer be harmless.</span><br></font></div><div class="gmail_default"><span style="color:rgb(0,0,0)"><font face="arial, sans-serif"><br></font></span></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)">So on all VMs this is not reliably thread-safe.  Even on the JIT VM the first use of any method (except a doit) is interpreted.  Once the JIT VM, once it has started up and the methods have been jitted, </span><span style="color:rgb(0,0,0)">"Processor activeProcess == Project current uiProcess" is thread-safe on Morphic, but not on MVC.  So we really shouldn't be using things like this.  They'll appear to work and in very rare circumstances they won't.  So let's please use the proper construct, Mutex.</span></font></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)"><br></span></font></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)"><br></span></font></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)">But that makes me realize that the effectiveProcess changes are unsafe on an interpreter VM (and hence we're on;y getting away with it on the JIT VM).  Se really need some way of saying that </span></font><span style="color:rgb(0,0,0);font-family:-webkit-standard;font-size:medium">ProcessorScheduler>>#activeProcess is atomic, e.g.</span></div><div class="gmail_default"><font face="arial, sans-serif"><span style="color:rgb(0,0,0)"><br></span></font></div><div class="gmail_default"><div class="gmail_default" style="color:rgb(0,0,0)">Process>>#effectiveProcess</div><div class="gmail_default" style="color:rgb(0,0,0)">        <noContextSwitch></div><div class="gmail_default" style="color:rgb(0,0,0)"><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>^effectiveProcess ifNil: [self]</div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">But I don't know how to implement this right now.  Note that we do have </div><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_default" style="color:rgb(0,0,0)">BlockClosure>>#valueNoContextSwitch</div><div class="gmail_default" style="color:rgb(0,0,0)"><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>"An exact copy of BlockClosure>>value except that this version will not preempt</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">     </span> the current process on block activation if a higher-priority process is runnable.</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">     </span> Primitive. Essential."</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">   </span><primitive: 221></div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>numArgs ~= 0 ifTrue:</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">           </span>[self numArgsError: 0].</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>self primitiveFailed</div><div class="gmail_default"><br></div><div class="gmail_default">FullBlockClosure>>#valueNoContextSwitch</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>"An exact copy of BlockClosure>>value except that this version will not preempt</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">     </span> the current process on block activation if a higher-priority process is runnable.</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">     </span> Primitive. Essential."</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">   </span><primitive: 209></div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>numArgs ~= 0 ifTrue:</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">           </span>[self numArgsError: 0].</div><div class="gmail_default"><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>self primitiveFailed</div><div class="gmail_default"><font face="arial, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, sans-serif">but the VM uses the primitive numbers to control context switching.  We don't have a mechanism the VM can use to label a normal method such as Process>>#effectiveProcess as not to allow an interrupt.</font></div><div class="gmail_default"><span style="font-family:-webkit-standard;font-size:medium"><br></span></div></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div id="gmail-m_-4475141367309418__MailbirdStyleContent" style="font-size:10pt;font-family:Arial;color:rgb(0,0,0);text-align:left" dir="ltr"><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Best,</span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Marcel</span></div><div></div>
                                        <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-top:20px;margin-left:0px;padding-left:10px;min-width:500px">
                        <p style="color:rgb(170,170,170);margin-top:10px">Am 23.01.2021 21:05:05 schrieb Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</a>>:</p><div style="font-family:Arial,Helvetica,sans-serif">On Fri, 22 Jan 2021, tim Rowledge wrote:<br><br>><br>><br>>> On 2021-01-22, at 5:26 PM, David T. Lewis <u></u> wrote:<br>>> <br>>> On Fri, Jan 22, 2021 at 02:03:10PM -0600, jaromir wrote:<br>>>> I ran the following in Squeak 5.3:<br>>>> <br>>>> TranscriptStream forceUpdate: false.<br>>>> [ 10000 timesRepeat: [ Transcript show: 'x' ] ] forkAt: 39<br>>>> <br>>>> When the Transcript window fills up, 'Message not understood' and 'Assertion<br>>>> failure' appear. I'm wondering is this a bug? Thanks. Jaromir<br>>>> <br>>>> <u></u> <br>>>> <br>>> <br>>> It certainly does appear to be a bug.<br>><br>> We had some discussion about it not so long ago; you can't use the Transcript to log bugs from Seaside very well, for example. Background processes, mutexs, that sort of thing. IIRC Levente offered an explanation?<br><br>It's simply not thread-safe.<br>If you want it to be thread-safe, you can pass your message to the UI <br>process to show it. Make sure your message is computed in its own process <br>and is passed as a precomputed string to avoid other kinds of race <br>conditions. E.g.:<br><br>| theMessage |<br>theMessage := 'Something very {1}.' format: { 'important' }.<br>Project current addDeferredUIMessage: [ Transcript show: theMessage; cr ].<br><br><br>Levente<br><br>><br>><br>> tim<br>> --<br>> tim Rowledge; <a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" target="_blank">http://www.rowledge.org/tim</a><br>> The hardness of the butter is proportional to the softness of the bread.<br><br><u></u><u></u></div></blockquote></div><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>