Threads are subroutines that can run concurrently. Every Haskell program begins with one thread, called the main thread. Starting an additional thread is called forking a thread.
To fork a thread, use the
forkIO function from the
Setting the output stream’s buffer mode to line-buffering will make the output of this example more readable.
f three times: Once in the main thread, and then twice in new forked threads.