Hi All,

   we have a serious misunderstanding in current versions of Squeak’s and Pharo’s Process>>isSuspended.
Squeak’s version reads

^myList isNil
Pharo’s reads
^myList isNil or: [ myList isEmpty ]
Process’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’s myList is always nil, so Squeak’s and Pharo’s are both wrong for the active process.
Processor activeProcess isSuspended => true (!!!)
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.
Processor waitingProcessesAt: Processor activePriority => a LinkedList()
Processor waitingProcessesAt: Processor lowestPriority => a LinkedList(a Process in ProcessorScheduler class>>idleProcess)
Here’s a couple of illustrative examples:
[Semaphore new wait] fork suspendingList
=> a LinkedList(a Process in [] in BlockClosure>>newProcess)
([Semaphore new wait] forkAt: Processor activePriority + 1) suspendingList
=> a Semaphore(a Process in [] in UndefinedObject>>DoIt)
In the first example above the new process isn’t running yet.  It’s runnable but hasn’t got a chance to run because the active process that created it is still running.  So the process’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.
So in fact, isSuspended should read something like
| myRunList |
myRunList := Processor waitingProcessesAt: priority.
^myList notNil and: [myList ~~ myRunList]
except that this isn’t atomic. But it isn’t the complete nonsense we have at the moment. Here’s an atomic version that answers the truth at the point that the question was asked:
| myPriority |
myPriority := priority.
ifNil: [false]
ifNotNil: [:list| list ~~ (Processor waitingProcessesAt: myPriority)]
We need tests like
self deny: Processor activeProcess isSuspended.

self deny: ([Semaphore new wait] forkAt: Processor activePriority) isSuspended.

self assert: ([Semaphore new wait] forkAt: Processor activePriority + 1) isSuspended.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: