3 ms·
"You can throw an exception to another thread, at any time;" "The other thread will receive the exception immediately, whatever it is doing." Does anybody know
by rkrzr 10y ago
"You can throw an exception to another thread, at any time;"
"The other thread will receive the exception immediately, whatever it is doing."
Does anybody know how this is implemented in the runtime system?
How does one thread communicate with another thread?
And how do you need to look at this for it not to be a side-effect?
Any insight is much appreciated.
- runeks 10y ago> And how do you need to look at this for it not to be a side-effect? I would look at it like this: while a function can be pure (no side effects), the thread in which it executes need not be a pure construct. It's a property of the runtime system, which, essentially, schedules pure functions to run inside green threads, to which exceptions can be thrown (which will terminate the execution of the pure function).
- marcosdumay 10y agoIt is not a side-effect because it is part of the execution model. In other words, it's one of the things you don't care about when writing a pure program, like how many times it runs, how many threads are running it, on what order it executes, etc. It does leak, but only on the IO monad.
- jwlato 10y agoI surely don't know as much as simonmar about this, but I think this is a rhetorical shortcut. My understanding is that when a Haskell thread receiving the exception needs to allocate on the heap, the executing context will instead raise the exception. As for why it's not a side effect, in Haskell all exceptions are considered to be bottom, the value that inhabits every type. Thus an exception can be raised anywhere and have any type. They can only be handled in IO though.