Hi Max, On Tue, Sep 16, 2014 at 11:05 AM, Max Leske <maxleske@gmail.com> wrote:
Hi
As always when I want to check if a process has died I get very confused by #isTerminated and Iâm wondering if I just donât get how itâs supposed to work or if there are others that share my confusion.
Old implementation:
isTerminated
self isActiveProcess ifTrue: [^ false]. ^suspendedContext isNil or: ["If the suspendedContext is the bottomContext it is the block in Process>>newProcess. If so, and the pc is greater than the startpc, the bock has alrteady sent and returned from value and there is nothing more to do." suspendedContext isBottomContext and: [ suspendedContext pc > suspendedContext startpc ] ]
Pharo 4 implementation:
isTerminated self isActiveProcess ifTrue: [^ false]. ^suspendedContext isNil or: ["If the suspendedContext is the bottomContext it is the block in Process>>newProcess. If so, and the pc is greater than the startpc, the bock has alrteady sent and returned from value and there is nothing more to do.â suspendedContext isBottomContext and: [ suspendedContext isDead not â<âââââââââââââââââââââââââ new" and: [ suspendedContext pc > suspendedContext startpc ] ] ]
The old implementation would break if the suspended context was dead (i.e. the pc was nil) because the send of #> would produce an MNU. The new implementation doesnât fix that, even though it looks like it at first glance: if the pc is nil, the #> send will still happen -> MNU.
Off the top of my head it would seem that it should be isDead or: [] not isDead not and: isTerminated self isActiveProcess ifTrue: [^ false]. ^suspendedContext isNil or: ["If the suspendedContext is the bottomContext it is the block in Process>>newProcess. If so, and the pc is greater than the startpc, the bock has alrteady sent and returned from value and there is nothing more to do.â suspendedContext isBottomContext and: [ suspendedContext isDead or: [ suspendedContext pc > suspendedContext startpc ] ] ]
isDead ^ pc isNil
and maybe (suspendedContext pc ifNil: [true] ifNotNil: [:pc| pc > suspendedContext startpc]) is more obvious. Anyway, neither implementation will reliably tell me if the process has
been terminated: - an inactive process will be suspended when #terminate is sent and report that it has not been terminated (#isSuspended -> true, #isTerminated -> false)
except that it *hasn't* been terminated, it is merely in the process of termination. It isn't terminated until all unwind blocks have run, right?
- a properly terminated process will raise an MNU (although apparently not always�)
but that's a bug the change I suggested will fix.
- all the states in between: no clue
I would like to know two things: 1. how can I check if a process has already *received* a #terminate? (I would then assume that the process will die eventually)
I don't think you can without putting a critical section around terminate and adding some process-specific variable that is set when you send terminate. termination is not instantaneous (unwind blocks have to be run), so it is potentially interruptible.
2. how can I check if a process is *actually* dead? (in case a âhalf deadâ process will still unwind or whatever)
see above.
What would be necessary to make those tests (or better ones) possible (rewrite the whole process implementation?)?
Cheers, Max
-- best, Eliot