Native Threads in the RTS
Sun, 1 Dec 2002 22:39:57 -0500 (EST)
On 29 Nov 2002, Alastair Reid wrote:
> Consider Haskell functions a,b,c,d and C functions A,B,C,D and a call
> a -> A -> b -> B -> c -> C -> d -> D
> That is, a calls A, calls b, calls B, calls ...
> Suppose we want A,B,C,D executed by the same foreign thread.
> Each of a,b,c,d are executed by different Haskell threads (because a
> new Haskell thread is spawned for each call into Haskell) so we have
> multiple Haskell threads associated with a single foreign thread.
It doesn't feel right to me that a,b,c,d are executed by different Haskell
threads. Why shouldn't they all be the *same* Haskell thread?
1. Reasonable exception handling across the Haskell/foreign boundary is
not currently supported, but if we imagine moving in that direction, it
would seem we'd want a single thread for the given example.
2. Calling from foreign code into Haskell to a bound foreign import will
require some special handling to ensure that a subsequent call out to
foreign code will use the same native thread. Why couldn't this special
handling select the same Haskell thread instead of creating a new one?