#fork and deterministic resumption of the resulting process
Paolo Bonzini
bonzini at gnu.org
Tue Feb 5 09:06:57 UTC 2008
> This will make sure that #fork has (for the purpose of resumption) the
> same semantics as forking at a lower priority has.
>
> What do people think about this?
Curiously, I prefer to have the *opposite* behavior in #fork, i.e.
always resume the forked process if the priority is equal. Note that
this wouldn't be an ultimate fix, because it could lead to an equally
wrong idiom,
MyClass>>startWorkerProcess
"worker is an instance variable"
[self runWorkerProcess] fork.
MyClass>>runWorkerProcess
"Run the worker process"
worker := Processor activeProcess.
[Processor activeProcess == worker] whileTrue:[
"...do the work..."
].
MyClass>>stopWorkerProcess
"Stop the worker process"
worker := nil. "let it terminate itself"
I'm with Terry on the correct idiom to use, i.e.
workerProcess := [self runWorkerProcess] newProcess.
workerProcess resume.
if you really do not want to use a separate instance variable. Another
possibility is to signal a Notification:
| running |
[running := true.
[running] whileTrue: [ ... ]]
on: StopRunning
do: [ :ex | running := false. ex resume ].
Paolo
More information about the Squeak-dev
mailing list
|