ghci and ghc -threaded broken with pipes & forking

Simon Marlow simonmarhaskell at gmail.com
Tue Mar 6 05:48:57 EST 2007


John Goerzen wrote:
> On Mon, Mar 05, 2007 at 03:20:05PM +0000, Ian Lynagh wrote:
>>> >From reading the docs, it sounds like forkIO keeps everything in a
>>> single OS thread/process.  Doesn't this mean that a program that uses
>>> forkIO instead of forkOS loses out on SMP machines?
>> You can use e.g. +RTS -N2 to use 2 OS threads.
> 
> That's rather ugly though, and doesn't "just work".  With other
> languages, I could just use OS threads, and let the OS schedule, say, 15
> threads across 2 CPUs, or 4 CPUs, or however I may have.

One day we might make this automatic, but you're missing the main point: what 
GHC gives you is lightweight threads that scale transparently on a 
multiprocessor.  You can create thousands of threads without worrying about 
performance, and therefore you are free to structure your program's concurrency 
according to the application's needs, not the demands of performance.  You don't 
have to limit the number of threads and do event-driven programming just because 
threads are too expensive.  And your program will scale on a multiprocessor 
without recompilation.

Cheers,
	Simon



More information about the Glasgow-haskell-users mailing list