Consider the following code:
process := [ (Delay forSeconds: 10) wait ]
forkAt: Processor userBackgroundPriority.
process terminate.
process isTerminated. "--> false"
process resume. "process has been suspended but not terminated"
(Delay forSeconds: 10) wait.
process isTerminated "--> true"
As you can see, the process won’t terminate until the block has been evaluated (i.e. after ten seconds in this case).
Is there a way to immediately terminate a process?
Also: does anyone have an idea why the block is evaluated in the first place?
Edit:
I can see why the block is evaluated. The problem with the above code is of course that I try to terminate the process before it has become active. Still, what if I don’t want to wait for the delay to expire?
After sending
terminateyour process is suspended (check by sendingisSuspended) so it will not run unless resumed. You get false fromisTerminatedbecause the process did not have a chance to start yet (look at the source code forisTerminatedto see why).So in fact your process is inactive and will be properly garbage collected once you let go of the reference, which for your purposes should be as good as “terminated”.
(Disclaimer: I was looking at the Squeak code, not Pharo, but this part of the system should be pretty much the same)