[Haskell-cafe] Re: -threaded

2007-12-14 Thread Simon Marlow

Maurí­cio wrote:


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).


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: -threaded

2007-12-14 Thread Ketil Malde
Simon Marlow [EMAIL PROTECTED] writes:

 Concurrency is supported just fine without -threaded.  You need
 -threaded if you want to:
  :
  3) write a multithreaded Haskell library or DLL

I thought -threaded (A.K.A. -smp, no?) only affected which runtime was
used, and thus was a linking option.  I do have a library that needs
-smp, but as far as I knew, the onus would be on the *applications* to
specify this when compiling/linking.  Is that incorrect?  Is there a
way for a library to inform the application about this?

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: -threaded

2007-12-14 Thread Simon Marlow

Ketil Malde wrote:

Simon Marlow [EMAIL PROTECTED] writes:


Concurrency is supported just fine without -threaded.  You need
-threaded if you want to:

  :

 3) write a multithreaded Haskell library or DLL


I thought -threaded (A.K.A. -smp, no?) only affected which runtime was
used, and thus was a linking option.  I do have a library that needs
-smp, but as far as I knew, the onus would be on the *applications* to
specify this when compiling/linking.  Is that incorrect?  Is there a
way for a library to inform the application about this?


Sorry, I was a bit ambiguous there: for case (3) I mean a Haskell library 
that you intend to call from C, or some other foreign language, using 
multiple OS threads.  You're absolutely right that for a Haskell library 
that you intend to call from Haskell, the -threaded option is used when the 
final program is linked, there's no way for the library itself to add it.


Cheers,
Simon
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe