Hi all,<br>
<br>
the docs on suspendedContext in the Process class comment say:<br>
<br>
    <i>if nil, then I am either the active process or I have been terminated.  If not nil it is the Context at the hot end of my stack</i><br>
<br>
To me, this would indicate the following invariant:<br>
<br>
    <font color="#800000">self</font><font color="#000000"> </font><font color="#000080">assert:</font><font color="#000000"> </font><font color="#000000">Processor</font><font color="#000000"> </font><font color="#000080">activeProcess</font><font color="#000000"> </font><font color="#000080">suspendedContext</font><font color="#000000"> </font><font color="#000080">isNil</font><font color="#000000">.</font><br>
<br>
However, this invariant is violated if you simulate this expression rather executing it:<br>
<br>
    <font color="#000000">(</font><font color="#000000">Process</font><font color="#000000"><br>
        </font><font color="#000080">forBlock:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">assert:</font><font color="#000000"> </font><font color="#000000">Processor</font><font color="#000000"> </font><font color="#000080">activeProcess</font><font color="#000000"> </font><font color="#000080">suspendedContext</font><font color="#000000"> </font><font color="#000080">isNil</font><font color="#008000">]</font><font color="#000000"><br>
        </font><font color="#000080">runUntil:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#000000">:</font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#000080">isDead</font><font color="#000000"> </font><font color="#000080">or:</font><font color="#000000"> </font><font color="#800080">[</font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#000080">selector</font><font color="#000000"> </font><font color="#000080">=</font><font color="#000000"> </font><font color="#000080">#defaultAction</font><font color="#800080">]</font><font color="#008000">]</font><font color="#000000">)</font><font color="#000000"><br>
            </font><font color="#000080">resume</font><font color="#000000">.</font><br>
<br>
Do you think this is a bug and should be fixed? We could do this by patching all assignors to suspendedContext in the 'changing suspended state' protocol on Process, maybe even as a small pattern like this:<br>
<br>
    <b>step</b><font color="#000000"><br>
<br>
</font>    <font color="#000000">    </font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#FF0000">doStep:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#000080">step</font><font color="#000000">]</font><br>
<br>
    <b>stepToCallee</b><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#008080">"Step until top context changes"</font><font color="#000000"><br>
<br>
        </font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#FF0000">doStep:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000000">:</font><font color="#000080">ctx</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"> </font><font color="#808080">ctxt</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"><br>
            </font><font color="#808080">ctxt</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#000080">ctx</font><font color="#000000">.</font><font color="#000000"><br>
            </font><font color="#008000">[</font><font color="#808080">ctxt</font><font color="#000000"> </font><font color="#000080">==</font><font color="#000000"> </font><font color="#000080">ctx</font><font color="#008000">]</font><font color="#000000"> </font><font color="#000080">whileTrue:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#808080">ctxt</font><font color="#000000"> </font><b>:=</b><font color="#000000"> </font><font color="#808080">ctxt</font><font color="#000000"> </font><font color="#000080">step</font><font color="#008000">]</font><font color="#000000">.</font><font color="#000000"><br>
            </font><font color="#808080">ctxt</font><font color="#000000">]</font><br>
<br>
    <b>doStep: </b><font color="#000080">aBlock</font><br>
    <br>
        <font color="#808080">|</font><font color="#000000"> </font><font color="#6B6B6B">ctxt</font><font color="#000000"> </font><font color="#808080">|</font><font color="#000000"><br>
        </font><font color="#6B6B6B">ctxt</font><font color="#000000"> </font><b>:=</b><font color="#000000"> suspendedContext.</font><font color="#000000"><br>
        suspendedContext </font><b>:=</b><font color="#000000"> </font><font color="#800000">nil</font><font color="#000000">.</font><font color="#000000"><br>
        </font><font color="#800000">^</font><font color="#000000"> suspendedContext </font><b>:=</b><font color="#000000"> </font><font color="#000000">Processor</font><font color="#000000"> </font><font color="#000080">activeProcess</font><font color="#000000"><br>
            </font><font color="#000080">evaluate:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#000080">aBlock</font><font color="#000000"> </font><font color="#000080">value:</font><font color="#000000"> </font><font color="#6B6B6B">ctxt</font><font color="#000000">]</font><font color="#000000"><br>
            </font><font color="#000080">onBehalfOf:</font><font color="#000000"> </font><font color="#800000">self</font><br>
<br>
Where <font color="#000080">#doStep:</font> would handle the effective process and read, set to nil, and set again the suspendedContext of the receiver. Disclaimer: The above is pseudocode only so far.<br>
<br>
Or isn't this worth the overhead and the invariant above has only to be valid for processes that are executed by the VM? :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font>