This file is indexed.

/usr/share/doc/libghc-extra-doc/html/Control-Concurrent-Extra.html is in libghc-extra-doc 1.4.10-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Control.Concurrent.Extra</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="file:///usr/share/javascript/mathjax/MathJax.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Control-Concurrent-Extra.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Control-Concurrent-Extra.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">extra-1.4.10: Extra functions I use.</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">Control.Concurrent.Extra</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Lock</a></li><li><a href="#g:2">Var</a></li><li><a href="#g:3">Barrier</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Extra functions for <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html">Control.Concurrent</a>.</p><p>This module includes three new types of <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent-MVar.html#t:MVar">MVar</a></code>, namely <code><a href="Control-Concurrent-Extra.html#t:Lock">Lock</a></code> (no associated value),
   <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code> (never empty) and <code><a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a></code> (filled at most once). See
   <a href="http://neilmitchell.blogspot.co.uk/2012/06/flavours-of-mvar_04.html">this blog post</a>
   for examples and justification.</p><p>If you need greater control of exceptions and threads
   see the <a href="http://hackage.haskell.org/package/slave-thread">slave-thread</a> package.
   If you need elaborate relationships between threads
   see the <a href="http://hackage.haskell.org/package/async">async</a> package.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html">Control.Concurrent</a></li><li class="src short"><a href="#v:getNumCapabilities">getNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:setNumCapabilities">setNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:withNumCapabilities">withNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:forkFinally">forkFinally</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> ()) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:once">once</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a)</li><li class="src short"><a href="#v:onceFork">onceFork</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a)</li><li class="src short"><span class="keyword">data</span> <a href="#t:Lock">Lock</a></li><li class="src short"><a href="#v:newLock">newLock</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a></li><li class="src short"><a href="#v:withLock">withLock</a> :: <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:withLockTry">withLockTry</a> :: <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a)</li><li class="src short"><span class="keyword">data</span> <a href="#t:Var">Var</a> a</li><li class="src short"><a href="#v:newVar">newVar</a> :: a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="Control-Concurrent-Extra.html#t:Var">Var</a> a)</li><li class="src short"><a href="#v:readVar">readVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:modifyVar">modifyVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (a, b)) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b</li><li class="src short"><a href="#v:modifyVar_">modifyVar_</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:withVar">withVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b</li><li class="src short"><span class="keyword">data</span> <a href="#t:Barrier">Barrier</a> a</li><li class="src short"><a href="#v:newBarrier">newBarrier</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a)</li><li class="src short"><a href="#v:signalBarrier">signalBarrier</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:waitBarrier">waitBarrier</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:waitBarrierMaybe">waitBarrierMaybe</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a)</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src">module <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html">Control.Concurrent</a></p></div><div class="top"><p class="src"><a id="v:getNumCapabilities" class="def">getNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> <a href="#v:getNumCapabilities" class="selflink">#</a></p><div class="doc"><p>Returns the number of Haskell threads that can run truly
simultaneously (on separate physical processors) at any given time.  To change
this value, use <code><a href="Control-Concurrent-Extra.html#v:setNumCapabilities">setNumCapabilities</a></code>.</p><p><em>Since: 4.4.0.0</em></p></div></div><div class="top"><p class="src"><a id="v:setNumCapabilities" class="def">setNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> () <a href="#v:setNumCapabilities" class="selflink">#</a></p><div class="doc"><p>Set the number of Haskell threads that can run truly simultaneously
(on separate physical processors) at any given time.  The number
passed to <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html#v:forkOn">forkOn</a></code> is interpreted modulo this value.  The initial
value is given by the <code>+RTS -N</code> runtime flag.</p><p>This is also the number of threads that will participate in parallel
garbage collection.  It is strongly recommended that the number of
capabilities is not set larger than the number of physical processor
cores, and it may often be beneficial to leave one or more cores free
to avoid contention with other processes in the machine.</p><p><em>Since: 4.5.0.0</em></p></div></div><div class="top"><p class="src"><a id="v:withNumCapabilities" class="def">withNumCapabilities</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Int.html#t:Int">Int</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a <a href="src/Control-Concurrent-Extra.html#withNumCapabilities" class="link">Source</a> <a href="#v:withNumCapabilities" class="selflink">#</a></p><div class="doc"><p>On GHC 7.6 and above with the <code>-threaded</code> flag, brackets a call to <code><a href="Control-Concurrent-Extra.html#v:setNumCapabilities">setNumCapabilities</a></code>.
   On lower versions (which lack <code><a href="Control-Concurrent-Extra.html#v:setNumCapabilities">setNumCapabilities</a></code>) this function just runs the argument action.</p></div></div><div class="top"><p class="src"><a id="v:forkFinally" class="def">forkFinally</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Either.html#t:Either">Either</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> ()) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Concurrent.html#t:ThreadId">ThreadId</a> <a href="#v:forkFinally" class="selflink">#</a></p><div class="doc"><p>Fork a thread and call the supplied function when the thread is about
 to terminate, with an exception or a returned value.  The function is
 called with asynchronous exceptions masked.</p><pre>forkFinally action and_then =
  mask $ \restore -&gt;
    forkIO $ try (restore action) &gt;&gt;= and_then</pre><p>This function is useful for informing the parent when a child
 terminates, for example.</p><p><em>Since: 4.6.0.0</em></p></div></div><div class="top"><p class="src"><a id="v:once" class="def">once</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a) <a href="src/Control-Concurrent-Extra.html#once" class="link">Source</a> <a href="#v:once" class="selflink">#</a></p><div class="doc"><p>Given an action, produce a wrapped action that runs at most once.
   If the function raises an exception, the same exception will be reraised each time.</p><pre>let x ||| y = do t1 &lt;- onceFork x; t2 &lt;- onceFork y; t1; t2
\(x :: IO Int) -&gt; void (once x) == return ()
\(x :: IO Int) -&gt; join (once x) == x
\(x :: IO Int) -&gt; (do y &lt;- once x; y; y) == x
\(x :: IO Int) -&gt; (do y &lt;- once x; y ||| y) == x</pre></div></div><div class="top"><p class="src"><a id="v:onceFork" class="def">onceFork</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a) <a href="src/Control-Concurrent-Extra.html#onceFork" class="link">Source</a> <a href="#v:onceFork" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Control-Concurrent-Extra.html#v:once">once</a></code>, but immediately starts running the computation on a background thread.</p><pre>\(x :: IO Int) -&gt; join (onceFork x) == x
\(x :: IO Int) -&gt; (do a &lt;- onceFork x; a; a) == x</pre></div></div><h1 id="g:1">Lock</h1><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Lock" class="def">Lock</a> <a href="src/Control-Concurrent-Extra.html#Lock" class="link">Source</a> <a href="#t:Lock" class="selflink">#</a></p><div class="doc"><p>Like an MVar, but has no value.
   Used to guarantees single-threaded access, typically to some system resource. 
   As an example:</p><pre>lock &lt;- <code><a href="Control-Concurrent-Extra.html#v:newLock">newLock</a></code>
let output = <code><a href="Control-Concurrent-Extra.html#v:withLock">withLock</a></code> . putStrLn
forkIO $ do ...; output &quot;hello&quot;
forkIO $ do ...; output &quot;world&quot;
</pre><p>Here we are creating a lock to ensure that when writing output our messages
   do not get interleaved. This use of MVar never blocks on a put. It is permissible,
   but rare, that a withLock contains a withLock inside it - but if so,
   watch out for deadlocks.</p></div></div><div class="top"><p class="src"><a id="v:newLock" class="def">newLock</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a> <a href="src/Control-Concurrent-Extra.html#newLock" class="link">Source</a> <a href="#v:newLock" class="selflink">#</a></p><div class="doc"><p>Create a new <code><a href="Control-Concurrent-Extra.html#t:Lock">Lock</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:withLock" class="def">withLock</a> :: <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a <a href="src/Control-Concurrent-Extra.html#withLock" class="link">Source</a> <a href="#v:withLock" class="selflink">#</a></p><div class="doc"><p>Perform some operation while holding <code><a href="Control-Concurrent-Extra.html#t:Lock">Lock</a></code>. Will prevent all other
   operations from using the <code><a href="Control-Concurrent-Extra.html#t:Lock">Lock</a></code> while the action is ongoing.</p></div></div><div class="top"><p class="src"><a id="v:withLockTry" class="def">withLockTry</a> :: <a href="Control-Concurrent-Extra.html#t:Lock">Lock</a> -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a) <a href="src/Control-Concurrent-Extra.html#withLockTry" class="link">Source</a> <a href="#v:withLockTry" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Control-Concurrent-Extra.html#v:withLock">withLock</a></code> but will never block. If the operation cannot be executed
   immediately it will return <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#v:Nothing">Nothing</a></code>.</p></div></div><h1 id="g:2">Var</h1><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Var" class="def">Var</a> a <a href="src/Control-Concurrent-Extra.html#Var" class="link">Source</a> <a href="#t:Var" class="selflink">#</a></p><div class="doc"><p>Like an MVar, but must always be full.
   Used to on a mutable variable in a thread-safe way.
   As an example:</p><pre>hits &lt;- <code><a href="Control-Concurrent-Extra.html#v:newVar">newVar</a></code> 0
forkIO $ do ...; <code><a href="Control-Concurrent-Extra.html#v:modifyVar_">modifyVar_</a></code> hits (+1); ...
i &lt;- <code><a href="Control-Concurrent-Extra.html#v:readVar">readVar</a></code> hits
print (<a href="HITS.html">HITS</a>,i)
</pre><p>Here we have a variable which we modify atomically, so modifications are
   not interleaved. This use of MVar never blocks on a put. No modifyVar
   operation should ever block, and they should always complete in a reasonable
   timeframe. A Var should not be used to protect some external resource, only
   the variable contained within. Information from a readVar should not be subsequently
   inserted back into the Var.</p></div></div><div class="top"><p class="src"><a id="v:newVar" class="def">newVar</a> :: a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="Control-Concurrent-Extra.html#t:Var">Var</a> a) <a href="src/Control-Concurrent-Extra.html#newVar" class="link">Source</a> <a href="#v:newVar" class="selflink">#</a></p><div class="doc"><p>Create a new <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code> with a value.</p></div></div><div class="top"><p class="src"><a id="v:readVar" class="def">readVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a <a href="src/Control-Concurrent-Extra.html#readVar" class="link">Source</a> <a href="#v:readVar" class="selflink">#</a></p><div class="doc"><p>Read the current value of the <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:modifyVar" class="def">modifyVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (a, b)) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b <a href="src/Control-Concurrent-Extra.html#modifyVar" class="link">Source</a> <a href="#v:modifyVar" class="selflink">#</a></p><div class="doc"><p>Modify a <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code> producing a new value and a return result.</p></div></div><div class="top"><p class="src"><a id="v:modifyVar_" class="def">modifyVar_</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> () <a href="src/Control-Concurrent-Extra.html#modifyVar_" class="link">Source</a> <a href="#v:modifyVar_" class="selflink">#</a></p><div class="doc"><p>Modify a <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code>, a restricted version of <code><a href="Control-Concurrent-Extra.html#v:modifyVar">modifyVar</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:withVar" class="def">withVar</a> :: <a href="Control-Concurrent-Extra.html#t:Var">Var</a> a -&gt; (a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b) -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> b <a href="src/Control-Concurrent-Extra.html#withVar" class="link">Source</a> <a href="#v:withVar" class="selflink">#</a></p><div class="doc"><p>Perform some operation using the value in the <code><a href="Control-Concurrent-Extra.html#t:Var">Var</a></code>,
   a restricted version of <code><a href="Control-Concurrent-Extra.html#v:modifyVar">modifyVar</a></code>.</p></div></div><h1 id="g:3">Barrier</h1><div class="top"><p class="src"><span class="keyword">data</span> <a id="t:Barrier" class="def">Barrier</a> a <a href="src/Control-Concurrent-Extra.html#Barrier" class="link">Source</a> <a href="#t:Barrier" class="selflink">#</a></p><div class="doc"><p>Starts out empty, then is filled exactly once. As an example:</p><pre>bar &lt;- <code><a href="Control-Concurrent-Extra.html#v:newBarrier">newBarrier</a></code>
forkIO $ do ...; val &lt;- ...; <code><a href="Control-Concurrent-Extra.html#v:signalBarrier">signalBarrier</a></code> bar val
print =&lt;&lt; <code><a href="Control-Concurrent-Extra.html#v:waitBarrier">waitBarrier</a></code> bar
</pre><p>Here we create a barrier which will contain some computed value.
   A thread is forked to fill the barrier, while the main thread waits
   for it to complete. A barrier has similarities to a future or promise
   from other languages, has been known as an IVar in other Haskell work,
   and in some ways is like a manually managed thunk.</p></div></div><div class="top"><p class="src"><a id="v:newBarrier" class="def">newBarrier</a> :: <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a) <a href="src/Control-Concurrent-Extra.html#newBarrier" class="link">Source</a> <a href="#v:newBarrier" class="selflink">#</a></p><div class="doc"><p>Create a new <code><a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:signalBarrier" class="def">signalBarrier</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> () <a href="src/Control-Concurrent-Extra.html#signalBarrier" class="link">Source</a> <a href="#v:signalBarrier" class="selflink">#</a></p><div class="doc"><p>Write a value into the Barrier, releasing anyone at <code><a href="Control-Concurrent-Extra.html#v:waitBarrier">waitBarrier</a></code>.
   Any subsequent attempts to signal the <code><a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a></code> will throw an exception.</p></div></div><div class="top"><p class="src"><a id="v:waitBarrier" class="def">waitBarrier</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> a <a href="src/Control-Concurrent-Extra.html#waitBarrier" class="link">Source</a> <a href="#v:waitBarrier" class="selflink">#</a></p><div class="doc"><p>Wait until a barrier has been signaled with <code><a href="Control-Concurrent-Extra.html#v:signalBarrier">signalBarrier</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:waitBarrierMaybe" class="def">waitBarrierMaybe</a> :: <a href="Control-Concurrent-Extra.html#t:Barrier">Barrier</a> a -&gt; <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#t:Maybe">Maybe</a> a) <a href="src/Control-Concurrent-Extra.html#waitBarrierMaybe" class="link">Source</a> <a href="#v:waitBarrierMaybe" class="selflink">#</a></p><div class="doc"><p>A version of <code><a href="Control-Concurrent-Extra.html#v:waitBarrier">waitBarrier</a></code> that never blocks, returning <code><a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Data-Maybe.html#v:Nothing">Nothing</a></code>
   if the barrier has not yet been signaled.</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>