Native Threads in the RTS

Wolfgang Thaller [email protected]
Mon, 2 Dec 2002 23:24:21 +0100


I've postponed writing up a new proposal again...

But I'm going to sum up some requirements that I would like to see 
fulfilled - to make it clearer to others why I'm proposing such strange 
things...

*) It should be possible for Haskell code to arrange that a sequence of 
calls to a given library are performed by the same native thread and 
that if an external library calls into Haskell, then any outgoing calls 
from Haskell are performed by the same native thread.

*) The specification should be implementable in a way that allows a lot 
of foreign calls to be made with no additional overhead with respect to 
GHC's current "unsafe" foreign calls.

*) The good performance of the existing lightweight "green" threads in 
GHC should not be sacrificed. Performance should still OK when using 
the new features with only a few threads (i.e. not more than commonly 
used from multithreaded C programs).

*) The specification shouldn't explicitly require lightweight "green" 
threads to exist. The specification should be implementable in a simple 
and obvious way in haskell systems that always use a 1:1 correspondence 
between Haskell threads and OS threads.

*) The specification shouldn't specify which particular OS thread 
should be used to execute Haskell code. It should be possible to 
implement it with e.g. a Haskell interpreter running in one OS thread 
that just uses other OS threads for foreign calls.

*) There should be no unexpected blocking. Especially, threadsafe calls 
should never cause other threads to block.

I'm currently stuck thinking about one particular problem that I 
discovered in my current version of the spec. What happens when an 
unbound Haskell thread calls a threadsafe foreign function which in 
turn calls a bound foreign exported function? Well, I think my current 
proposal says relatively clearly what's supposed to happen, but I 
discovered it's not as easy to fit that in the current implementation 
of GHC as I thought... in fact it might be quite difficult. I'll have 
to do more thinking before I can be sure, though.


That's it for today,

Regards,

Wolfgang