Login  Register

Re: How to terminate a process ?

Posted by Chris Uppal-3 on Dec 30, 2004; 12:14pm
URL: https://forum.world.st/How-to-terminate-a-process-tp3372531p3372543.html

Joseph Frippiat wrote:

> myProcess terminate.
> myProcess := nil.

You may find it easier not to use Process>>terminate, but just set a flag that
the background Process checks periodically.  Not only is that less likely to
result in the Process terminating itself, but I think it is also safer in
general.

I often (well, in-so-far as I use background threads at all ;-) overload the
'myProcess' variable for this purpose.  It's a bit hacky, but it does have the
advantage that the front-end can start a new backgound process without worrying
about existing (obsolete) ones.  Code like

    "in background proc"
    [myProcess == Pocessor activeProcess] whileTrue:
        [self oneStepOfBackgroundActivity].

Then the foregound process can either set 'myProc' to nil to stop the
backgounder, or start a new backgrounder and assign it to 'myProcess' which
will implicitly kill the existing one.

    -- chris