[Haskell-cafe] Re: -threaded
simonmarhaskell at gmail.com
Fri Dec 14 05:26:57 EST 2007
> I see in the documentation and in many
> messages in this list that, if you want
> multithreading in your program, you
> need to use -threaded in ghc.
Concurrency is supported just fine without -threaded. You need -threaded
if you want to:
1) make foreign calls that do not block other threads
2) use multiple CPUs
3) write a multithreaded Haskell library or DLL
Some library functions use foreign calls, for example
System.Process.waitForProcess, so if you want to use them without blocking
other threads you need -threaded.
From an implementation perspective, -threaded enables OS-thread support in
the runtime. Without -threaded, everything runs in a single OS thread.
The features listed above all require multiple OS threads.
> Why isn't that option default? Does
> it imply some kind of overhead?
There may be an overhead, because the runtime has to use synchronisation in
various places. Hopefully the overhead is negligible for most things.
It's not the default mostly for historical reasons, and because there are
people who don't like to get multiple OS threads unless they ask for it.
Also there are one or two things that don't work well with -threaded
(Gtk2Hs, and System.Posix.forkProcess).
More information about the Haskell-Cafe