Uncaught exceptions in subprocesses send message to parent.
Cat's Eye Technologies
13 years ago
113 | 113 |
|
114 | 114 |
### Concurrency and Exceptions ###
|
115 | 115 |
|
116 | |
* Establish the relationship between exceptions and processes -- if a
|
117 | |
process raises an exception that it does not catch, it should send
|
118 | |
a message to its parent (the process that spawned it.)
|
119 | |
|
120 | 116 |
* Fuller tests for exceptions.
|
121 | 117 |
|
122 | 118 |
* Add richer concurrency primitives (`call` and `respond`, which assume
|
51 | 51 |
process has started, we set up an appropriate IEnv and evaluate
|
52 | 52 |
the macro in that.
|
53 | 53 |
|
54 | |
TODO: the exception handler in the new IEnv should not be `stop`,
|
55 | |
but rather something that sends a message to the parent.
|
56 | |
|
57 | |
TODO: should we put the parent in the IEnv, too?
|
58 | |
|
59 | 54 |
TODO: should the final continuation send a message to the parent
|
60 | 55 |
too?
|
61 | 56 |
|
|
66 | 61 |
> launch chan = do
|
67 | 62 |
> thread <- myThreadId
|
68 | 63 |
> let parent = getPid ienv
|
69 | |
> let myIenv = newIEnv (stop) thread chan
|
|
64 |
> let myIenv = newIEnv (makeMsgSendingExcHandler parent) thread chan
|
70 | 65 |
> let expr = Pair macro $ Pair parent Null
|
71 | 66 |
> eval env myIenv expr (\x -> do return Null)
|
72 | 67 |
> return ()
|
|
68 |
|
|
69 |
> makeMsgSendingExcHandler pid =
|
|
70 |
> \value -> do
|
|
71 |
> writeChan (getChan pid) (Pair (Symbol "uncaught-exception") value)
|
|
72 |
> return Null
|
73 | 73 |
|
74 | 74 |
Now the functions exported by this Robin module.
|
75 | 75 |
|
218 | 218 |
| (recv message message)))
|
219 | 219 |
= hello
|
220 | 220 |
|
|
221 |
If an exception is raised, but not caught, in a process, that process
|
|
222 |
sends a message to this effect to the process that spawned it,
|
|
223 |
immediately before terminating.
|
|
224 |
|
|
225 |
| (robin (0 . 1) (small (0 . 1) concurrency (0 . 1))
|
|
226 |
| (bind worker (spawn (fun (parent)
|
|
227 |
| (bind x (head ())
|
|
228 |
| (send parent (literal hi) 0))))
|
|
229 |
| (recv message message)))
|
|
230 |
= (uncaught-exception expected-pair)
|
|
231 |
|
221 | 232 |
### `msgs?` ###
|
222 | 233 |
|
223 | 234 |
`msgs?` evaluates to `#t` if the current process has one or more messages
|