#fork and deterministic resumption of the resulting process

Keith Hodges keith_hodges at yahoo.co.uk
Mon Feb 4 22:09:12 UTC 2008


Andreas Raab 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:
>
> MyClass>>startWorkerProcess
>     "worker is an instance variable"
>     worker:= [self runWorkerProcess] fork.
>
> MyClass>>runWorkerProcess
>     "Run the worker process"
>     [Processor activeProcess == worker] whileTrue:[
>         "...do the work..."
>     ].
>
> MyClass>>stopWorkerProcess
>     "Stop the worker process"
>     worker := nil. "let it terminate itself"
>
> Those of you who can immediately tell what the problem is should get a
> medal for an outstanding knack of analyzing concurrency problems ;-)
 In this situation the idiom I use is something like this

MyClass>>startWorkerProcess
    "worker is an instance variable"
    worker:= [self runWorkerProcess]  newProcess.
    worker resume.
 
:-)

Keith





More information about the Squeak-dev mailing list