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 runtime is that if a light-weight thread has blocked a system call, the whole program will block. On the threaded runtime, GHC can schedule light-weight threads to run on other system threads while the other thread is blocked on a system...