[POLL] Process>>terminate
Boris.Gaertner
Boris.Gaertner at gmx.net
Mon Oct 15 10:39:13 UTC 2007
"Igor Stasenko" <siguctua at gmail.com> wrote:
> Hi all,
>
> I just found a side-effect of Process>>terminate call, leading to
> evaluate all #ensure: and #ifCurtailed: blocks in process before its
> really got terminated.
>
> I just wonder, how many of you wrote #ensure: thinking that it will be
> evaluated only during normal execution flow and never when process is
> terminated in the middle of execution.
>
> I just had conversation with Goran on IRC, and he was surprised by not
> knowing this too.
> It needless to say that writing a code which uses #ensure: without
> knowing such details could lead to errors which is hard to catch and
> reproduce.
Agreed, but that is a question of documentation.
The problem is, in my opinion, that #ensure: and #ifCurtailed: are
often explained as exception handlers. That is wrong.
The methods #ensure: and #ifCurtailed: are designed to provide
cleanup actions for stack unwinding. The stack is unwound
when
* pending method calls are dropped during exception
handling (methods Exception>return and Exception>return:
are used to do that)
* pending method calls are left with a jump (To do that,
you pass a block with a return statement (e.g. ^self) as
argument to another method)
* a process is terminated
So these are the situations that cause the evaluation of
an ensure/ifCurtailed block.
I think it is perhaps better to call #ensure: and #ifCurtailed:
finalizers.Unfortunately, that word has also a lot of slightly
different meanings in different programming languages.
> I thought that #terminate behavior was just stop process at point
> where its currently running and never try to evaluate anything else in
> its context.
>
> A terminating in current way could be considered as 'soft terminate'
> or gracious terminate. But then we lack of 'hard' or unconditional
> terminate, which just stops process without trying to unwind stack.
>
> And the poll question is: how many of you thought that #terminate is
> 'hard' terminate, not 'soft'. :)
Some years ago, when I wrote a tutorial about the MVC user interface
and Smalltalk in general, I learned all these details.
Greetings, Boris
More information about the Squeak-dev
mailing list
|