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?
Without -threaded , the Haskell process uses a single OS thread only, and multithreaded foreign calls are not supported.
GHC implements some major extensions to Haskell to support concurrent and parallel programming.
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.
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);
[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).
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.
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.
Also, you can get the latest status of multicore Haskell from this SO question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With