New Bound Threads Proposal
Wolfgang Thaller
wolfgang.thaller at gmx.net
Wed May 14 09:10:43 EDT 2003
John Meacham wrote:
> On Tue, May 06, 2003 at 03:19:17PM +0200, Wolfgang Thaller wrote:
>> 1) bind the "main" Haskell thread to the "main" OS thread
>> [...]
> I don't see any problem with 1. It is no worse than the situation in
> other languages and is significantly better in that Haskell can easily
> pass around IO actions for the main thread to run. plus, any library
> documentation for other languages will carry over into Haskell easily.
Does anyone else have objections against always binding the "main"
Haskell thread to the "main" OS thread?
The thing is, if we always make the main thread bound, the
implementation in the GHC RTS becomes simpler and much more "beautiful".
Any possible performance penalty due to the use of a bound thread can
be easily worked around like this:
main = do
finish <- newEmptyMVar
forkIO (realMain >> putMVar finish ())
takeMVar finish
<technical details>
A non-bound "main" thread would be the only non-bound thread that has
to return somewhere.
In the previous threaded RTS, this was solved by keeping a global
variable "mainMainThread"; when that thread ends, the RTS does a
"threadsafe" foreign call to shutdownHaskellAndExit.
Also there's that strange distinction between rts_evalLazyIO and
rts_mainLazyIO in order to avoid spawning another OS thread.
On program termination, shutdownHaskellAndExit has to make sure that
there's a second worker thread anyway, because it can't use
rts_mainLazyIO for executing finalizers.
All those hacks would go away if the "main" Haskell thread is always
bound to the "main" IO thread.
</technical details>
Cheers,
Wolfgang
More information about the FFI
mailing list