Personal tools

Concurrency

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m
(fixing dead link)
Line 13: Line 13:
 
: STM was added to GHC 6.4, and is described in the paper [http://research.microsoft.com/~simonpj/papers/stm/index.htm Composable memory transactions]. The paper [http://research.microsoft.com/~simonpj/papers/stm/lock-free.htm Lock-free data structures using Software Transactional Memory in Haskell] gives further examples of concurrent programming using STM.
 
: STM was added to GHC 6.4, and is described in the paper [http://research.microsoft.com/~simonpj/papers/stm/index.htm Composable memory transactions]. The paper [http://research.microsoft.com/~simonpj/papers/stm/lock-free.htm Lock-free data structures using Software Transactional Memory in Haskell] gives further examples of concurrent programming using STM.
   
* '''Foreign function interface'''. If you are calling foreign functions in a concurrent program, you need to know about ''bound threads''. They are described in a Haskell workshop paper, [http://research.microsoft.com/~simonpj/Papers/conc-ffi/index.htm Extending the Haskell Foreign Function Interface with Concurrency]. The GHC Commentary [http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/rts-libs/multi-thread.html Supporting multi-threaded interoperation] contains more detailed explanation of cooperation between FFI calls and multi-threaded runtime.
+
* '''Foreign function interface'''. If you are calling foreign functions in a concurrent program, you need to know about ''bound threads''. They are described in a Haskell workshop paper, [http://research.microsoft.com/~simonpj/Papers/conc-ffi/index.htm Extending the Haskell Foreign Function Interface with Concurrency]. The GHC Commentary [http://darcs.haskell.org/ghc/docs/comm/rts-libs/multi-thread.html Supporting multi-threaded interoperation] contains more detailed explanation of cooperation between FFI calls and multi-threaded runtime.
   
 
* '''Nested Data Parallelism'''. For an approach to exploiting the implicit parallelism in array programs for multiprocessors, see [[GHC/Data Parallel Haskell|Data Parallel Haskell]] (work in progress).
 
* '''Nested Data Parallelism'''. For an approach to exploiting the implicit parallelism in array programs for multiprocessors, see [[GHC/Data Parallel Haskell|Data Parallel Haskell]] (work in progress).

Revision as of 03:23, 24 December 2008

Contents

1 Concurrent programming in GHC

This page contains notes and information about how to write concurrent programs in GHC.

Please feel free to add stuff here (Edit page link at the bottom).

1.1 Starting points

  • Software Transactional Memory (STM) is a new way to coordinate concurrent threads. There's a separate Wiki page devoted to STM.
STM was added to GHC 6.4, and is described in the paper Composable memory transactions. The paper Lock-free data structures using Software Transactional Memory in Haskell gives further examples of concurrent programming using STM.
  • Nested Data Parallelism. For an approach to exploiting the implicit parallelism in array programs for multiprocessors, see Data Parallel Haskell (work in progress).


1.2 Using concurrency in GHC

  • The GHC manual gives a few useful flags that control scheduling (not usually necessary) RTS options.


1.3 Multiprocessor GHC

As of version 6.5, GHC supports running programs in parallel on an SMP or multi-core machine. How to do it:

  • You need to link your program using the -threaded switch. (NOTE: previously it was necessary to compile all code, including libraries, with the -smp switch, this is no longer the case. The -smp flag is now a synonym for -threaded).
  • Run the program with +RTS -N2 to use 2 threads, for example. You should use a -N value equal to the number of CPU cores on your machine (not including Hyper-threading cores).
  • Concurrent threads (forkIO and forkOS) will run in parallel, and you can also use the par combinator and Strategies from the Control.Parallel.Strategies module to create parallelism.
  • Use +RTS -sstderr for timing stats.

1.4 Links to related work on parallel and distributed Haskell (many based on GHC)

2 Problems with GHC implementation before 6.6.1

There are critical differences between the description in the paper "Asynchronous exceptions in Haskell by Simon Marlow, Simon Peyton Jones, Andy Moran and John Reppy, PLDI'01." the implementation in GHC 6.4 and GHC 6.6 today.

Some of the bad effects are described here under throwTo & block statements considered harmful.

The versions of GHC from 6.6.1 and up have fixed the problematical difference.