mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
lecture 16: fix typo
This commit is contained in:
+1
-1
@@ -4821,7 +4821,7 @@ TODO explain `some` and `many`
|
||||
<span id="cb444-11"><a href="#cb444-11" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span> ()</span></code></pre></div>
|
||||
<pre><code>Prelude Control.Concurrent> concurrency
|
||||
AABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABB</code></pre>
|
||||
<p>The operation <code>forkIO :: IO () -> IO ThreadId</code> takes an IO operation and starts running it in the backgroud. It produces a <code>ThreadId</code> that can be used to e.g. terminate the thread.</p>
|
||||
<p>The operation <code>forkIO :: IO () -> IO ThreadId</code> takes an IO operation and starts running it in the background. It produces a <code>ThreadId</code> that can be used to e.g. terminate the thread.</p>
|
||||
<p>If we want to add actual communication between threads, we can use abstractions like <a href="https://hackage.haskell.org/package/base-4.16.4.0/docs/Control-Concurrent-MVar.html"><code>MVar</code></a> (a mutable thread-safe variable) or <a href="https://hackage.haskell.org/package/base-4.16.4.0/docs/Control-Concurrent-Chan.html"><code>Chan</code></a> (a queue).</p>
|
||||
<p>Here’s a simple example where one thread writes a value to an <code>MVar</code> and another one waits for them and prints them. An <code>MVar</code> works like a mailbox: it is either empty or full. Calling <code>takeMVar</code> on an empty box waits for the box to get filled (with a <code>putMVar</code>). Symmetrically, trying to <code>putMVar</code> into a full box waits until the box is empty.</p>
|
||||
<div class="sourceCode" id="cb446"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb446-1"><a href="#cb446-1" aria-hidden="true" tabindex="-1"></a><span class="ot">takeMVar ::</span> <span class="dt">MVar</span> a <span class="ot">-></span> <span class="dt">IO</span> a</span>
|
||||
|
||||
Reference in New Issue
Block a user