<div dir="ltr">Hi All,<div><br></div><div>   we have a serious misunderstanding in current versions of Squeak&#39;s and Pharo&#39;s Process&gt;&gt;isSuspended.</div><div><br></div><div>Squeak&#39;s version reads</div><div><br class="">isSuspended</div><div><span class="" style="white-space:pre">        </span>^myList isNil</div><div><br></div><div>Pharo&#39;s reads</div><div><br></div><div><div>isSuspended</div><div><span class="" style="white-space:pre">        </span>^myList isNil or: [ myList isEmpty ]</div><div><br></div><div>Process&#39;s myList holds the list a process is on when it is not running.  There is only one running process at any one time, Processor activeProcess.  The active process&#39;s myList is always nil, so Squeak&#39;s and Pharo&#39;s are both wrong for the active process.</div><div><br></div><div>Processor activeProcess isSuspended =&gt; true (!!!)</div><div><br></div><div>A process may be runnable, but not running (which follows form there being only one running process, the active process, at any one time).  If it is runnable but not running its list is one of the runnable process lists in the scheduler, e.g.</div><div><div><br></div><div>Processor waitingProcessesAt: Processor activePriority =&gt; a LinkedList()</div><div>Processor waitingProcessesAt: Processor lowestPriority =&gt; a LinkedList(a Process in ProcessorScheduler class&gt;&gt;idleProcess)</div></div><div><br></div><div>Here&#39;s a couple of illustrative examples:</div><div><br></div><div><div>[Semaphore new wait] fork suspendingList</div><div>=&gt; a LinkedList(a Process in [] in BlockClosure&gt;&gt;newProcess)</div><div><br></div><div>([Semaphore new wait] forkAt: Processor activePriority + 1) suspendingList</div><div>=&gt; a Semaphore(a Process in [] in UndefinedObject&gt;&gt;DoIt)</div></div><div><br></div><div>In the first example above the new process isn&#39;t running yet.  It&#39;s runnable but hasn&#39;t got a chance to run because the active process that created it is still running.  So the process&#39;s list is Processor waitingProcessesAt: Processor activePriority.  In the second example the process has got to run, because, having higher priority, it has preempted the active process that created it.  So it suspends waiting on the semaphore.</div><div><br></div><div><br></div><div>So in fact, isSuspended should read something like</div><div><br></div><div>isSuspended</div><div><span style="white-space:pre">        </span>| myRunList |</div><div><span style="white-space:pre">        myRunList := </span>Processor waitingProcessesAt: priority.<br></div><div><span style="white-space:pre">        ^myList notNil and: [myList ~~ myRunList]</span><br></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">except that this isn&#39;t atomic.  But it isn&#39;t the complete nonsense we have at the moment.  Here&#39;s an atomic version that answers the truth at the point that the question was asked:</span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">isSuspended</span></div><div><span style="white-space:pre">        </span><span style="white-space:pre">| myPriority |</span></div><div><span style="white-space:pre">        myPriority := priority.</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">        ^myList</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">        </span><span style="white-space:pre">        ifNil: [false]</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">        </span><span style="white-space:pre">        ifNotNil: [:list| list ~~ (</span>Processor waitingProcessesAt: myPriority)]<span style="white-space:pre"><br></span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">We need tests like</span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">    self deny: Processor activeProcess isSuspended.</span></div>    self deny: ([Semaphore new wait] forkAt: Processor activePriority) isSuspended.</div><div><div><span style="white-space:pre">    self assert: </span>([Semaphore new wait] forkAt: Processor activePriority + 1) isSuspended.</div><div><br></div><div 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>