Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 6e204a966e8c42d976f99a1700ce5f20 > files > 2248

ghc-7.4.2-4.mga5.i586.rpm

<!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>Data.IORef</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Data-IORef.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>portable</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">Data.IORef</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">IORefs
</a><ul><li><a href="#g:2">Memory Model
</a></li></ul></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Mutable references in the IO monad.
</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"><span class="keyword">data</span>  <a href="#t:IORef">IORef</a> a</li><li class="src short"><a href="#v:newIORef">newIORef</a> ::  a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-IORef.html#t:IORef">IORef</a> a)</li><li class="src short"><a href="#v:readIORef">readIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:writeIORef">writeIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:modifyIORef">modifyIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; (a -&gt; a) -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:atomicModifyIORef">atomicModifyIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; (a -&gt; (a, b)) -&gt; <a href="System-IO.html#t:IO">IO</a> b</li><li class="src short"><a href="#v:mkWeakIORef">mkWeakIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-Mem-Weak.html#t:Weak">Weak</a> (<a href="Data-IORef.html#t:IORef">IORef</a> a))</li></ul></div><div id="interface"><h1 id="g:1">IORefs
</h1><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:IORef" class="def">IORef</a> a </p><div class="doc"><p>A mutable variable in the <code><a href="System-IO.html#t:IO">IO</a></code> monad
</p></div><div class="subs instances"><p id="control.i:IORef" class="caption collapser" onclick="toggleSection('i:IORef')">Instances</p><div id="section.i:IORef" class="show"><table><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable1">Typeable1</a> <a href="Data-IORef.html#t:IORef">IORef</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> (<a href="Data-IORef.html#t:IORef">IORef</a> a)</td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:newIORef" class="def">newIORef</a> ::  a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-IORef.html#t:IORef">IORef</a> a)</p><div class="doc"><p>Build a new <code><a href="Data-IORef.html#t:IORef">IORef</a></code>
</p></div></div><div class="top"><p class="src"><a name="v:readIORef" class="def">readIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Read the value of an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>
</p></div></div><div class="top"><p class="src"><a name="v:writeIORef" class="def">writeIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Write a new value into an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>
</p></div></div><div class="top"><p class="src"><a name="v:modifyIORef" class="def">modifyIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; (a -&gt; a) -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>Mutate the contents of an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>
</p></div></div><div class="top"><p class="src"><a name="v:atomicModifyIORef" class="def">atomicModifyIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; (a -&gt; (a, b)) -&gt; <a href="System-IO.html#t:IO">IO</a> b</p><div class="doc"><p>Atomically modifies the contents of an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>.
</p><p>This function is useful for using <code><a href="Data-IORef.html#t:IORef">IORef</a></code> in a safe way in a multithreaded
 program.  If you only have one <code><a href="Data-IORef.html#t:IORef">IORef</a></code>, then using <code><a href="Data-IORef.html#v:atomicModifyIORef">atomicModifyIORef</a></code> to
 access and modify it will prevent race conditions.
</p><p>Extending the atomicity to multiple <code><a href="Data-IORef.html#t:IORef">IORef</a></code>s is problematic, so it
 is recommended that if you need to do anything more complicated
 then using <code><a href="Control-Concurrent-MVar.html#t:MVar">MVar</a></code> instead is a good idea.
</p></div></div><div class="top"><p class="src"><a name="v:mkWeakIORef" class="def">mkWeakIORef</a> ::  <a href="Data-IORef.html#t:IORef">IORef</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a> -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="System-Mem-Weak.html#t:Weak">Weak</a> (<a href="Data-IORef.html#t:IORef">IORef</a> a))</p><div class="doc"><p>Make a <code><a href="System-Mem-Weak.html#t:Weak">Weak</a></code> pointer to an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>, using the second argument as a finalizer
 to run when <code><a href="Data-IORef.html#t:IORef">IORef</a></code> is garbage-collected
</p></div></div><h2 id="g:2">Memory Model
</h2><div class="doc"><p>In a concurrent program, <code><a href="Data-IORef.html#t:IORef">IORef</a></code> operations may appear out-of-order
  to another thread, depending on the memory model of the underlying
  processor architecture.  For example, on x86, loads can move ahead
  of stores, so in the following example:
</p><pre>  maybePrint :: IORef Bool -&gt; IORef Bool -&gt; IO ()
  maybePrint myRef yourRef = do
    writeIORef myRef True
    yourVal &lt;- readIORef yourRef
    unless yourVal $ putStrLn &quot;critical section&quot;

  main :: IO ()
  main = do
    r1 &lt;- newIORef False
    r2 &lt;- newIORef False
    forkIO $ maybePrint r1 r2
    forkIO $ maybePrint r2 r1
    threadDelay 1000000
</pre><p>it is possible that the string <code><a href="critical section.html">critical section</a></code> is printed
  twice, even though there is no interleaving of the operations of the
  two threads that allows that outcome.  The memory model of x86
  allows <code><a href="Data-IORef.html#v:readIORef">readIORef</a></code> to happen before the earlier <code><a href="Data-IORef.html#v:writeIORef">writeIORef</a></code>.
</p><p>The implementation is required to ensure that reordering of memory
  operations cannot cause type-correct code to go wrong.  In
  particular, when inspecting the value read from an <code><a href="Data-IORef.html#t:IORef">IORef</a></code>, the
  memory writes that created that value must have occurred from the
  point of view of the current therad.
</p><p><code><a href="Data-IORef.html#v:atomicModifyIORef">atomicModifyIORef</a></code> acts as a barrier to reordering.  Multiple
  <code><a href="Data-IORef.html#v:atomicModifyIORef">atomicModifyIORef</a></code> operations occur in strict program order.  An
  <code><a href="Data-IORef.html#v:atomicModifyIORef">atomicModifyIORef</a></code> is never observed to take place ahead of any
  earlier (in program order) <code><a href="Data-IORef.html#t:IORef">IORef</a></code> operations, or after any later
  <code><a href="Data-IORef.html#t:IORef">IORef</a></code> operations.
</p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>