From 59735e76d37c5470504be4d64206cd49660e1324 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Mon, 12 May 2025 12:31:19 +0300 Subject: [PATCH] lecture 16: fix typo --- part2.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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