inter-process signaling
Stephen Pair
stephen at pairhome.net
Fri Sep 19 21:17:58 UTC 2003
Ned Konz wrote:
>On Friday 19 September 2003 11:56 am, Stephen Pair wrote:
>
>
>>One of the things that crossed my mind not too long ago is that it
>>would be nice if we could signal exceptions in another process.
>>For example:
>>
>> Error new messageText: 'some error message'; signalProcess:
>>someProcess
>>
>>Or,
>>
>> someProcess signal: (Error new messageText: 'some error message';
>>yourself)
>>
>>This could be useful for graceful termination of processes (among
>>many other things)...unwind actions could always happen in the
>>process where they were defined. The default action of a Terminate
>>exception would be to terminate the active process. Here's the
>>method that seems to do the trick:
>>
>>Process>>signal: anException
>>
>> Processor activeProcess == self ifTrue: [^anException signal].
>> suspendedContext := MethodContext
>> sender: suspendedContext
>> receiver: self
>> method: thisContext method
>> arguments: (Array with: anException).
>>
>>
>>
>
>Thanks!
>
>I've asked for this several times and no one has come up with it yet.
>
>One obvious use of this is to provide Semaphore>>wait methods that
>raise an exception on a timeout.
>
Of course, if your process happens to be waiting on a Semaphore, sending
#signal: to the process will not wake it up (nothing will happen until
the semaphore gets signaled)...you could add a line to the end of that
method to suspend and resume (ie. "self suspend; resume") and that will
wake it up...but, what I'd really like is a way of waking it up to
process the exception and when you resume the exception have the process
go back into a state where it's still waiting on the original semaphore
(if it hadn't been signaled in the interim). I had a solution for that,
but it seems to have a tendency to crash the VM. ;)
- Stephen
More information about the Squeak-dev
mailing list
|