[squeak-dev] Refactoring #terminate to get rid of 'cannot return' errors etc.

Jaromir Matas m at jaromir.net
Sun Mar 21 20:12:02 UTC 2021


Hi Christoph, all:

> your
> proposal would not directly allow us to remove the current #isTerminated
> logic but only extend it, right? Because there could still be processes
> not
> using the new #terminated marker and thus requiring us to keep the old
> mechanisms. 

On second thought I think the proposal would allow us to simplify the
current #isTerminated logic. It's actually a matter of a policy: do we want
users to create processes other than the "newProcess" way? If not than we
can remove the condition checking the last instruction of the bottom
context, because newProcess no longer needs it, leaving just one condition:
is the process inside the #terminated method? (after eliminating defunct
processes). Like this:

Process >> isTerminated
	"Answer if the receiver is terminated, i.e. if the receiver is not active
and 
	one of the following conditions is met:
	(1) the receiver is a defunct process (suspendedContext = nil or pc = nil)
	(2) the receiver is suspended within a method with isTerminated pragma"

	self isActiveProcess ifTrue: [^false].
	^suspendedContext isNil or: [
		suspendedContext isDead or: [
			(suspendedContext method pragmaAt: #isTerminated) notNil]]

I used a new pragma instead of hardcoding the class and the selector of the
terminal method:

Process >> terminated
	"When I reach this method, I'm terminated. Suspending or terminating me is
harmless."
	<isTerminated>
	
	thisContext terminateTo: nil.   "sets thisContext sender to nil"
	self suspend.
	^thisContext restart

You can check it out in this changeset: 
Refactor_#terminate_2_without_atEnd.cs
<http://forum.world.st/file/t372955/Refactor_%23terminate_2_without_atEnd.cs>  
What do you think?
best,



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


More information about the Squeak-dev mailing list