[Pharo-project] Fwd: Improving a Process termination procedure
FYI ---------- Forwarded message ---------- From: Igor Stasenko <siguctua@gmail.com> Date: 2009/5/1 Subject: Re: Improving a Process termination procedure To: The general-purpose Squeak developers list <squeak-dev@lists.squeakfoundation.org> Another improvement would be to marry the process termination with exception handling, and nicely signal ProcessTerminatedException. This offers many practical benefits, since then we could write: [ ... ] on: ProcessTerminatedException do: [:ex | Â "oh man we're been terminated" ]. But i'm not expert in exception handling. Can someone give me a sample, how to signal such exception in potential #terminateFromContext: method? 2009/5/1 Igor Stasenko <siguctua@gmail.com>:
There are a potential of having incorrect behavior , when terminating a preempted or waiting process:
with introduction of ProcessLocalVariable, it is essential that context unwinding procedure should be performed only for currently active process.
Here the proposal how to ensure this:
if terminating process is not active process we should do the following:
suspendedContext := proc suspendedContext. currentProces := Processor activeProcess. proc suspendedContext: Â [ Â Processor activeProcess terminateFromContext: suspendedContext. Processor switchToProcess: currentProcess ] asContext. Processor switchToProcess: proc.
here #switchToProcess: is explicit switch (bypassing scheduling logic).
If we don't care about immediate termination of process and getting back to process who initiated termination as soon as possible, then simply do: process terminateSoon.
which can be implemented as:
Process>>terminateSoon | termContext | termContext := suspendedContext. suspendedContext := [ Â self terminateFromContext: termContext. self suspend ] asContext. Processor yield.
-- Best regards, Igor Stasenko AKA sig.
-- Best regards, Igor Stasenko AKA sig. -- Best regards, Igor Stasenko AKA sig.
participants (1)
-
Igor Stasenko