September 2017
Beginner to intermediate
396 pages
9h 46m
English
The IORef a represents a mutable reference in an the IO monad. In this recipe, we used forkIO run an IO() action for tracker in a separate thread. The function work runs in the main thread. It uses atomicModifyIORef' to atomically increment the counter. This function will prevent race conditions for one IORef. Note that there are two versions of atomicModifyIORef. The atomicModifyIORef version is a lazy version (the operation done may not be evaluated immediately), whereas atomicModifyIORef' is a strict version. Finally, we kill the tracker thread with the killThread function.
Read now
Unlock full access