diff --git a/part2.html b/part2.html index 344dc22..820283d 100644 --- a/part2.html +++ b/part2.html @@ -4821,7 +4821,7 @@ TODO explain `some` and `many` return ()
Prelude Control.Concurrent> concurrency
AABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB
-The operation forkIO :: IO () -> IO ThreadId takes an IO operation and starts running it in the backgroud. It produces a ThreadId that can be used to e.g. terminate the thread.
The operation forkIO :: IO () -> IO ThreadId takes an IO operation and starts running it in the background. It produces a ThreadId that can be used to e.g. terminate the thread.
If we want to add actual communication between threads, we can use abstractions like MVar (a mutable thread-safe variable) or Chan (a queue).
Here’s a simple example where one thread writes a value to an MVar and another one waits for them and prints them. An MVar works like a mailbox: it is either empty or full. Calling takeMVar on an empty box waits for the box to get filled (with a putMVar). Symmetrically, trying to putMVar into a full box waits until the box is empty.
takeMVar :: MVar a -> IO a