Tutorial by Examples

Haskell supports many forms of concurrency and the most obvious being forking a thread using forkIO. The function forkIO :: IO () -> IO ThreadId takes an IO action and returns its ThreadId, meanwhile the action will be run in the background. We can demonstrate this quite succinctly using ghci: ...
It is very easy to pass information between threads using the MVar a type and its accompanying functions in Control.Concurrent: newEmptyMVar :: IO (MVar a) -- creates a new MVar a newMVar :: a -> IO (MVar a) -- creates a new MVar with the given value takeMVar :: MVar a -> IO a -- retrieve...
Another powerful & mature concurrency tool in Haskell is Software Transactional Memory, which allows for multiple threads to write to a single variable of type TVar a in an atomic manner. TVar a is the main type associated with the STM monad and stands for transactional variable. They're used m...

Page 1 of 1