Concurrency
concurrencyicon.icon
Overview
Communication methods
Shared memory
All threads can access the same memory and communicate by modifying and inspecting mutable variables.
Very convenient (if large amounts of data are shared).
Potentially risky (race conditions, ...).
Message passing
Communication via messages sent between threads.
More overhead if large amounts of data are shared.
Less risky.
Well-known libraries
STM
MVars
IORef
Control.Concurrent
hackage link
forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
Executes the second argument once the thread is about to finish, whether normally or via an exception.
Example codes
Chat Server
TChan
Server Pattern, perform transaction
Shouting server
Useful link
Locks, Actors, And Stm In Pictures
Useful link(Japanese)
「Haskellによる並列・並行プログラミング」を読了した
第14回 Haskellでメッセージ通信を使う利点