[squeak-dev] The Inbox: Kernel-jar.1376.mcz

Jaromir Matas m at jaromir.net
Mon Mar 1 23:41:25 UTC 2021


Hi Eliot,

> 
> I like this.  But isn't this a little bit better?
> 
> isTerminated
>      "Answer if the receiver is terminated, or at least terminating."
>       self isActiveProcess ifTrue: [^ false].
>      ^suspendedContext isNil
>        or: ["If the suspendedContext is the bottomContext and the pc is at
> the endPC, 
>              then there is nothing more to do."
>              suspendedContext isBottomContext
>              and: [suspendedContext pc >= suspendedContext endPC 
>                      or: [suspendedContext closure isNil
>                              and: [suspendedContext methodClass == Process
>                              and: [suspendedContext selector ==
> #terminate]]]]]

delightful! Thanks ;)


Just for my curiosity - would this be considered a bad style (or is a math
like logical expression better):


isTerminated
	"Answer if the receiver is terminated, or at least terminating.
	If the suspendedContext is the bottomContext and the pc is at the endPC, 
	then there is nothing more to do.
	If an active process is terminated, it means it was suspended inside the 
	#terminate method leaving pc < endPC, so it needs to be caught separately"
	
	self isActiveProcess ifTrue: [^false].
	suspendedContext ifNil: [^true].
	suspendedContext isBottomContext ifFalse: [^false].
	suspendedContext pc >= suspendedContext endPC ifTrue: [^true].
	^suspendedContext closure isNil
		and: [suspendedContext methodClass == Process
		and: [suspendedContext selector == #terminate]]


> I'm also tempted to state in a comment why being in other than a block in
> Process>>#terminate implies the methods is essentially done terminating. 
> And there in lies the rub, to quote Shakespeare.  


My attempted explanation in the comment above but I'm not sure...


> Would a hack like adding a first temporary in Process>>#terminate called
> e.g. terminationStatus and having Process>>terminate assign to it when
> termination is essentially complete be better?
> 
> e.g.
> 
> isTerminated
>      "Answer if the receiver is terminated, or at least terminating."
>       self isActiveProcess ifTrue: [^ false].
>      ^suspendedContext isNil
>        or: ["If the suspendedContext is the bottomContext and the pc is at
> the endPC, 
>              then there is nothing more to do."
>              suspendedContext isBottomContext
>              and: [suspendedContext pc >= suspendedContext endPC 
>                      or: [suspendedContext closure isNil
>                              and: [suspendedContext methodClass == Process
>                              and: [suspendedContext selector == #terminate
>                              and: [(suspendedContext localAt: 1) ==
> #terminated]]]]]]

> 

I tried to figure out whether you just wanted to detect termination status
as early as possible or also something else... 

I guess the condition should be (not tested):

isTerminated
	"Answer if the receiver is terminated, or at least terminating."
	self isActiveProcess ifTrue: [^ false].
	^suspendedContext isNil
	  or: ["If the suspendedContext is the bottomContext and the pc is at the
endPC, 
		then there is nothing more to do."
		suspendedContext isBottomContext
		and: [suspendedContext pc >= suspendedContext endPC 
			or: [(suspendedContext localAt: 1) == #terminated]]]

... because `suspendedContext closure isNil` etc. only catches terminating a
suspended process. So to also cover terminating the active process we can, I
guess,  safely remove this condition. I'm not sure though about the localAt:
1 - what if other non-terminating process had it with the same #terminated -
is it ok?


Also - #isSuspended suffers with the same problem as #isTerminated; I'll
take a look at it next.

Thanks,

Best regards









-----
^[^ Jaromir
--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html


More information about the Squeak-dev mailing list