HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Yhc/RTS/Concurrency

< Yhc | RTS

Concurrency is now a standard part of Yhc.

Two of the biggest issues are detailed here, along with their solutions.

The first thing to note is that concurrency is implemented in Yhc by the interpretter running some instructions for one process, then some more instructions for the next process and so on.

This is rather than using one OS thread per Haskell process because all processes can access the global heap, so if using OS threads it would be necessary to either lock every heap access (incredibly slow) or use some of the truely nasty tricks that concurrent GHC uses.

1 Supporting Multiple Execution Stacks

The first problem, is that originally we only had one stack but now every process needs its own stack. After considering possible options I decided the easiest way was:

2 Blocking I/O and FFI calls

Now going back, the approach of running some instructions from one thread then some more from another is fine providing every instruction runs quickly. They all do, with one exception, PRIMITIVE. This is because PRIMITIVE is used for IO actions/FFI calls.

The solution? Well the basic idea is "just spawn an OS thread to do the IO action while the main thread continues running Haskell".

In detail, when PRIMITIVE is called for an IO action/FFI call:

There is a simple optimisation used which is if there is only one ready process in the program then it doesn't bother using a seperate thread, it just does the IO action directly.

Retrieved from "http://haskell.org/haskellwiki/Yhc/RTS/Concurrency"

This page has been accessed 2,370 times. This page was last modified 11:46, 26 March 2006. Recent content is available under a simple permissive license.