#fork and deterministic resumption of the resulting process

Igor Stasenko siguctua at gmail.com
Tue Feb 5 02:21:16 UTC 2008


On 04/02/2008, Andreas Raab <andreas.raab at gmx.de> wrote:
> Hi -
>
> In my never-ending quest for questionable behavior in multi-threaded
> situations just today I ran into a pattern which is dangerously common
> in our code. It basically goes like this:
>

Hmm, IMO, you wanting to kill two rabbits in one shot..

Why not write like following:

 MyClass>>startWorkerProcess
         "worker is an instance variable"
        running := true.
        worker := [self runWorkerProcess] fork.

 MyClass>>runWorkerProcess
         "Run the worker process"
         [running] whileTrue:[
                 "...do the work..."
         ].

 MyClass>>stopWorkerProcess
         "Stop the worker process"
        running := false. "let it terminate itself"

Yes, you will need an additional inst var - 'running', but i think
it's reasonable: controlling a process in context of scheduler
operations, where you need it's handle, and controlling when it's
should terminate graciously (by setting running flag to false), is
different things.

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list