Runtime System and threads

The GHC Runtime System comes in two flavors: threaded and non-threaded. For truly single-threaded applications, it's usually better to use the default non-threaded runtime, because there's more overhead in the threaded one. The non-threaded runtime features a scheduler for light-weight GHC threads (created via forkIO), providing for single-threaded concurrent programming.

Usually though, a concurrent program benefits from being multi-threaded – that is, using multiple CPU capabilities triggered via the -N<n> RTS flag when compiled with -threaded. The Runtime System creates one system thread for every capability and schedules light-weight threads to run in parallel on its system threads.

An important caveat with the non-threaded ...

Get Haskell High Performance Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.