Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Concurrent Haskell still restricted to a single OS thread?

In a 2005 research paper it said

Concurrent Haskell is currently implemented only for a uni-processor. The runtime schedules lightweight Haskell thread within a single operating system thread. Haskell threads are only suspended at well-defined “safe points”; they cannot be pre-empted at arbitrary moments.

Has this changed or is Concurrent Haskell still restricted to a single OS thread?

like image 859
Jonathan Allen Avatar asked Aug 11 '10 06:08

Jonathan Allen


People also ask

Is Haskell single threaded?

Without -threaded , the Haskell process uses a single OS thread only, and multithreaded foreign calls are not supported.

Does Haskell support concurrency?

GHC implements some major extensions to Haskell to support concurrent and parallel programming.

Is Haskell multi threaded?

Thread primitives For explicit concurrency and/or parallelism, Haskell implementations have a light-weight thread system that schedules logical threads on the available operating system threads. These light and cheap threads can be created with forkIO.

Why is Haskell good for concurrency?

Parallel and concurrent programming is much easier in Haskell: it's pure, which means that there are no mutations to observe and all data can be shared between threads freely; it supports modern techniques like STM (among many other options for parallel and concurrent programming);


3 Answers

[edit: the question only mentions Concurrent Haskell, but the paper referenced is, I believe, "Composable Memory Transactions", the paper in which Haskell STM was first described. Please correct me if I'm wrong here.]

STM works just fine on multiple cores now. The parallel implementation was first shipped in GHC 6.6, and uses a fine-grained two-phase locking strategy; that is, to commit a transaction the implementation first attempts to lock each variable involved in the transaction, then commits the changes, and finally unlocks all the variables. Acquiring a lock does not block: if the lock is already held, then the transaction aborts and retries (this avoids the usual lock-order-reversal deadlock that would apply if lock acquisition was blocking).

This STM implementation is certainly not the fastest - the literature describes many alternative techniques that would result in better performance, but GHC's implementation is relatively straightforward and doesn't involve any global locks (transactions operating on distinct sets of variables can proceed in parallel without interference).

like image 58
Simon Marlow Avatar answered Oct 05 '22 05:10

Simon Marlow


GHC can use multi-cores for Concurrent and Parallel Haskell since 2004. Concurrent, Parallel, Nested Data Parallel Haskell all use the same multi-threaded runtime.

like image 20
snk_kid Avatar answered Oct 05 '22 03:10

snk_kid


GHC Haskell runs well on multicores

GHC Haskell programs, since 2004, run multiple Haskell threads over multiple OS threads, which are distributed over multiple cores.

  • The initial design as implemented in GHC
  • Performance improvements to support parallel futures ("sparks").
  • A tutorial showing how to get speedups using all the major concurrency mechanisms on a multicore.

Also, you can get the latest status of multicore Haskell from this SO question.

like image 25
Don Stewart Avatar answered Oct 05 '22 05:10

Don Stewart