<!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>GHC.Conc</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_GHC-Conc.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.3.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>non-portable (GHC extensions)</td></tr><tr><th>Stability</th><td>internal</td></tr><tr><th>Maintainer</th><td>cvs-ghc@haskell.org</td></tr></table><p class="caption">GHC.Conc</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Forking and suchlike </a></li><li><a href="#g:2">Waiting </a></li><li><a href="#g:3">TVars </a></li><li><a href="#g:4">Miscellaneous </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Basic concurrency stuff. </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:ThreadId">ThreadId</a> = <a href="#v:ThreadId">ThreadId</a> <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:ThreadId-35-">ThreadId#</a></li><li class="src short"><a href="#v:forkIO">forkIO</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:forkIOUnmasked">forkIOUnmasked</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:forkOnIO">forkOnIO</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:forkOnIOUnmasked">forkOnIOUnmasked</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:numCapabilities">numCapabilities</a> :: <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:numSparks">numSparks</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></li><li class="src short"><a href="#v:childHandler">childHandler</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:myThreadId">myThreadId</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></li><li class="src short"><a href="#v:killThread">killThread</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:throwTo">throwTo</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> e -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:par">par</a> :: a -> b -> b</li><li class="src short"><a href="#v:pseq">pseq</a> :: a -> b -> b</li><li class="src short"><a href="#v:runSparks">runSparks</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:yield">yield</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:labelThread">labelThread</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="Data-Char.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:ThreadStatus">ThreadStatus</a> <ul class="subs"><li>= <a href="#v:ThreadRunning">ThreadRunning</a> </li><li>| <a href="#v:ThreadFinished">ThreadFinished</a> </li><li>| <a href="#v:ThreadBlocked">ThreadBlocked</a> <a href="GHC-Conc.html#t:BlockReason">BlockReason</a> </li><li>| <a href="#v:ThreadDied">ThreadDied</a> </li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:BlockReason">BlockReason</a> <ul class="subs"><li>= <a href="#v:BlockedOnMVar">BlockedOnMVar</a> </li><li>| <a href="#v:BlockedOnBlackHole">BlockedOnBlackHole</a> </li><li>| <a href="#v:BlockedOnException">BlockedOnException</a> </li><li>| <a href="#v:BlockedOnSTM">BlockedOnSTM</a> </li><li>| <a href="#v:BlockedOnForeignCall">BlockedOnForeignCall</a> </li><li>| <a href="#v:BlockedOnOther">BlockedOnOther</a> </li></ul></li><li class="src short"><a href="#v:threadStatus">threadStatus</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadStatus">ThreadStatus</a></li><li class="src short"><a href="#v:threadDelay">threadDelay</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:registerDelay">registerDelay</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> <a href="Data-Bool.html#t:Bool">Bool</a>)</li><li class="src short"><a href="#v:threadWaitRead">threadWaitRead</a> :: <a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:threadWaitWrite">threadWaitWrite</a> :: <a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:closeFdWith">closeFdWith</a> :: (<a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>) -> <a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><span class="keyword">newtype</span> <a href="#t:STM">STM</a> a = <a href="#v:STM">STM</a> (<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:State-35-">State#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a> -> (#<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:State-35-">State#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a>, a#))</li><li class="src short"><a href="#v:atomically">atomically</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:retry">retry</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:orElse">orElse</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:throwSTM">throwSTM</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:catchSTM">catchSTM</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => <a href="GHC-Conc.html#t:STM">STM</a> a -> (e -> <a href="GHC-Conc.html#t:STM">STM</a> a) -> <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:alwaysSucceeds">alwaysSucceeds</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:always">always</a> :: <a href="GHC-Conc.html#t:STM">STM</a> <a href="Data-Bool.html#t:Bool">Bool</a> -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:TVar">TVar</a> a = <a href="#v:TVar">TVar</a> (<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:TVar-35-">TVar#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a> a)</li><li class="src short"><a href="#v:newTVar">newTVar</a> :: a -> <a href="GHC-Conc.html#t:STM">STM</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> a)</li><li class="src short"><a href="#v:newTVarIO">newTVarIO</a> :: a -> <a href="System-IO.html#t:IO">IO</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> a)</li><li class="src short"><a href="#v:readTVar">readTVar</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:readTVarIO">readTVarIO</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:writeTVar">writeTVar</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> a -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:unsafeIOToSTM">unsafeIOToSTM</a> :: <a href="System-IO.html#t:IO">IO</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</li><li class="src short"><a href="#v:withMVar">withMVar</a> :: <a href="Control-Concurrent-MVar.html#t:MVar">MVar</a> a -> (a -> <a href="System-IO.html#t:IO">IO</a> b) -> <a href="System-IO.html#t:IO">IO</a> b</li><li class="src short"><span class="keyword">type</span> <a href="#t:Signal">Signal</a> = <a href="Foreign-C-Types.html#t:CInt">CInt</a></li><li class="src short"><span class="keyword">type</span> <a href="#t:HandlerFun">HandlerFun</a> = <a href="Foreign-ForeignPtr.html#t:ForeignPtr">ForeignPtr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:setHandler">setHandler</a> :: <a href="GHC-Conc.html#t:Signal">Signal</a> -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> (<a href="GHC-Conc.html#t:HandlerFun">HandlerFun</a>, <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a>) -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> (<a href="GHC-Conc.html#t:HandlerFun">HandlerFun</a>, <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a>))</li><li class="src short"><a href="#v:runHandlers">runHandlers</a> :: <a href="Foreign-ForeignPtr.html#t:ForeignPtr">ForeignPtr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="GHC-Conc.html#t:Signal">Signal</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:ensureIOManagerIsRunning">ensureIOManagerIsRunning</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:setUncaughtExceptionHandler">setUncaughtExceptionHandler</a> :: (<a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:getUncaughtExceptionHandler">getUncaughtExceptionHandler</a> :: <a href="System-IO.html#t:IO">IO</a> (<a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>)</li><li class="src short"><a href="#v:reportError">reportError</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:reportStackOverflow">reportStackOverflow</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ThreadId" class="def">ThreadId</a> </p><div class="doc"><p>A <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> is an abstract type representing a handle to a thread. <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> is an instance of <code><a href="Data-Eq.html#t:Eq">Eq</a></code>, <code><a href="Data-Ord.html#t:Ord">Ord</a></code> and <code><a href="Text-Show.html#t:Show">Show</a></code>, where the <code><a href="Data-Ord.html#t:Ord">Ord</a></code> instance implements an arbitrary total ordering over <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code>s. The <code><a href="Text-Show.html#t:Show">Show</a></code> instance lets you convert an arbitrary-valued <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> to string form; showing a <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> value is occasionally useful when debugging or diagnosing the behaviour of a concurrent program. </p><p><em>Note</em>: in GHC, if you have a <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code>, you essentially have a pointer to the thread itself. This means the thread itself can't be garbage collected until you drop the <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code>. This misfeature will hopefully be corrected at a later date. </p><p><em>Note</em>: Hugs does not provide any operations on other threads; it defines <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> as a synonym for (). </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ThreadId" class="def">ThreadId</a> <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:ThreadId-35-">ThreadId#</a></td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><p id="control.i:ThreadId" class="caption collapser" onclick="toggleSection('i:ThreadId')">Instances</p><div id="section.i:ThreadId" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable.html#t:Typeable">Typeable</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:1">Forking and suchlike </h1><div class="top"><p class="src"><a name="v:forkIO" class="def">forkIO</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></p><div class="doc"><p>Sparks off a new thread to run the <code><a href="System-IO.html#t:IO">IO</a></code> computation passed as the first argument, and returns the <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> of the newly created thread. </p><p>The new thread will be a lightweight thread; if you want to use a foreign library that uses thread-local storage, use <code>Control.Concurrent.forkOS</code> instead. </p><p>GHC note: the new thread inherits the <em>masked</em> state of the parent (see <code>Control.Exception.mask</code>). </p><p>The newly created thread has an exception handler that discards the exceptions <code><a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></code>, <code><a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></code>, and <code><a href="Control-Exception-Base.html#v:ThreadKilled">ThreadKilled</a></code>, and passes all other exceptions to the uncaught exception handler (see <code><a href="GHC-Conc.html#v:setUncaughtExceptionHandler">setUncaughtExceptionHandler</a></code>). </p></div></div><div class="top"><p class="src"><a name="v:forkIOUnmasked" class="def">forkIOUnmasked</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></p><div class="doc"><p>Like <code><a href="GHC-Conc.html#v:forkIO">forkIO</a></code>, but the child thread is created with asynchronous exceptions unmasked (see <code>Control.Exception.mask</code>). </p></div></div><div class="top"><p class="src"><a name="v:forkOnIO" class="def">forkOnIO</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></p><div class="doc"><p>Like <code><a href="GHC-Conc.html#v:forkIO">forkIO</a></code>, but lets you specify on which CPU the thread is created. Unlike a <code><a href="GHC-Conc.html#v:forkIO">forkIO</a></code> thread, a thread created by <code><a href="GHC-Conc.html#v:forkOnIO">forkOnIO</a></code> will stay on the same CPU for its entire lifetime (<code><a href="GHC-Conc.html#v:forkIO">forkIO</a></code> threads can migrate between CPUs according to the scheduling policy). <code><a href="GHC-Conc.html#v:forkOnIO">forkOnIO</a></code> is useful for overriding the scheduling policy when you know in advance how best to distribute the threads. </p><p>The <code><a href="Data-Int.html#t:Int">Int</a></code> argument specifies the CPU number; it is interpreted modulo <code><a href="GHC-Conc.html#v:numCapabilities">numCapabilities</a></code> (note that it actually specifies a capability number rather than a CPU number, but to a first approximation the two are equivalent). </p></div></div><div class="top"><p class="src"><a name="v:forkOnIOUnmasked" class="def">forkOnIOUnmasked</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></p><div class="doc"><p>Like <code><a href="GHC-Conc.html#v:forkOnIO">forkOnIO</a></code>, but the child thread is created with asynchronous exceptions unmasked (see <code>Control.Exception.mask</code>). </p></div></div><div class="top"><p class="src"><a name="v:numCapabilities" class="def">numCapabilities</a> :: <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>the value passed to the <code>+RTS -N</code> flag. This is the number of Haskell threads that can run truly simultaneously at any given time, and is typically set to the number of physical CPU cores on the machine. </p></div></div><div class="top"><p class="src"><a name="v:numSparks" class="def">numSparks</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p><div class="doc"><p>Returns the number of sparks currently in the local spark pool </p></div></div><div class="top"><p class="src"><a name="v:childHandler" class="def">childHandler</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:myThreadId" class="def">myThreadId</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadId">ThreadId</a></p><div class="doc"><p>Returns the <code><a href="GHC-Conc.html#t:ThreadId">ThreadId</a></code> of the calling thread (GHC only). </p></div></div><div class="top"><p class="src"><a name="v:killThread" class="def">killThread</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="GHC-Conc.html#v:killThread">killThread</a></code> raises the <code><a href="Control-Exception-Base.html#v:ThreadKilled">ThreadKilled</a></code> exception in the given thread (GHC only). </p><pre> killThread tid = throwTo tid ThreadKilled </pre></div></div><div class="top"><p class="src"><a name="v:throwTo" class="def">throwTo</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> e -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> raises an arbitrary exception in the target thread (GHC only). </p><p><code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> does not return until the exception has been raised in the target thread. The calling thread can thus be certain that the target thread has received the exception. This is a useful property to know when dealing with race conditions: eg. if there are two threads that can kill each other, it is guaranteed that only one of the threads will get to kill the other. </p><p>Whatever work the target thread was doing when the exception was raised is not lost: the computation is suspended until required by another thread. </p><p>If the target thread is currently making a foreign call, then the exception will not be raised (and hence <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> will not return) until the call has completed. This is the case regardless of whether the call is inside a <code><a href="Control-Exception-Base.html#v:mask">mask</a></code> or not. </p><p>Important note: the behaviour of <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> differs from that described in the paper "Asynchronous exceptions in Haskell" (<a href="http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm">http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm</a>). In the paper, <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is non-blocking; but the library implementation adopts a more synchronous design in which <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> does not return until the exception is received by the target thread. The trade-off is discussed in Section 9 of the paper. Like any blocking operation, <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is therefore interruptible (see Section 5.3 of the paper). Unlike other interruptible operations, however, <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is <em>always</em> interruptible, even if it does not actually block. </p><p>There is no guarantee that the exception will be delivered promptly, although the runtime will endeavour to ensure that arbitrary delays don't occur. In GHC, an exception can only be raised when a thread reaches a <em>safe point</em>, where a safe point is where memory allocation occurs. Some loops do not perform any memory allocation inside the loop and therefore cannot be interrupted by a <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code>. </p><p>Blocked <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is fair: if multiple threads are trying to throw an exception to the same target thread, they will succeed in FIFO order. </p></div></div><div class="top"><p class="src"><a name="v:par" class="def">par</a> :: a -> b -> b</p></div><div class="top"><p class="src"><a name="v:pseq" class="def">pseq</a> :: a -> b -> b</p></div><div class="top"><p class="src"><a name="v:runSparks" class="def">runSparks</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Internal function used by the RTS to run sparks. </p></div></div><div class="top"><p class="src"><a name="v:yield" class="def">yield</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>The <code><a href="GHC-Conc.html#v:yield">yield</a></code> action allows (forces, in a co-operative multitasking implementation) a context-switch to any other currently runnable threads (if any), and is occasionally useful when implementing concurrency abstractions. </p></div></div><div class="top"><p class="src"><a name="v:labelThread" class="def">labelThread</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="Data-Char.html#t:String">String</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="GHC-Conc.html#v:labelThread">labelThread</a></code> stores a string as identifier for this thread if you built a RTS with debugging support. This identifier will be used in the debugging output to make distinction of different threads easier (otherwise you only have the thread state object's address in the heap). </p><p>Other applications like the graphical Concurrent Haskell Debugger (<a href="http://www.informatik.uni-kiel.de/~fhu/chd/">http://www.informatik.uni-kiel.de/~fhu/chd/</a>) may choose to overload <code><a href="GHC-Conc.html#v:labelThread">labelThread</a></code> for their purposes as well. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ThreadStatus" class="def">ThreadStatus</a> </p><div class="doc"><p>The current status of a thread </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ThreadRunning" class="def">ThreadRunning</a></td><td class="doc"><p>the thread is currently runnable or running </p></td></tr><tr><td class="src"><a name="v:ThreadFinished" class="def">ThreadFinished</a></td><td class="doc"><p>the thread has finished </p></td></tr><tr><td class="src"><a name="v:ThreadBlocked" class="def">ThreadBlocked</a> <a href="GHC-Conc.html#t:BlockReason">BlockReason</a></td><td class="doc"><p>the thread is blocked on some resource </p></td></tr><tr><td class="src"><a name="v:ThreadDied" class="def">ThreadDied</a></td><td class="doc"><p>the thread received an uncaught exception </p></td></tr></table></div><div class="subs instances"><p id="control.i:ThreadStatus" class="caption collapser" onclick="toggleSection('i:ThreadStatus')">Instances</p><div id="section.i:ThreadStatus" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="GHC-Conc.html#t:ThreadStatus">ThreadStatus</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="GHC-Conc.html#t:ThreadStatus">ThreadStatus</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="GHC-Conc.html#t:ThreadStatus">ThreadStatus</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:BlockReason" class="def">BlockReason</a> </p><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:BlockedOnMVar" class="def">BlockedOnMVar</a></td><td class="doc"><p>blocked on on <code><a href="Control-Concurrent-MVar.html#t:MVar">MVar</a></code> </p></td></tr><tr><td class="src"><a name="v:BlockedOnBlackHole" class="def">BlockedOnBlackHole</a></td><td class="doc"><p>blocked on a computation in progress by another thread </p></td></tr><tr><td class="src"><a name="v:BlockedOnException" class="def">BlockedOnException</a></td><td class="doc"><p>blocked in <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> </p></td></tr><tr><td class="src"><a name="v:BlockedOnSTM" class="def">BlockedOnSTM</a></td><td class="doc"><p>blocked in <code><a href="GHC-Conc.html#v:retry">retry</a></code> in an STM transaction </p></td></tr><tr><td class="src"><a name="v:BlockedOnForeignCall" class="def">BlockedOnForeignCall</a></td><td class="doc"><p>currently in a foreign call </p></td></tr><tr><td class="src"><a name="v:BlockedOnOther" class="def">BlockedOnOther</a></td><td class="doc"><p>blocked on some other resource. Without <code>-threaded</code>, I/O and <code>threadDelay</code> show up as <code><a href="GHC-Conc.html#v:BlockedOnOther">BlockedOnOther</a></code>, with <code>-threaded</code> they show up as <code><a href="GHC-Conc.html#v:BlockedOnMVar">BlockedOnMVar</a></code>. </p></td></tr></table></div><div class="subs instances"><p id="control.i:BlockReason" class="caption collapser" onclick="toggleSection('i:BlockReason')">Instances</p><div id="section.i:BlockReason" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="GHC-Conc.html#t:BlockReason">BlockReason</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="GHC-Conc.html#t:BlockReason">BlockReason</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="GHC-Conc.html#t:BlockReason">BlockReason</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:threadStatus" class="def">threadStatus</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="GHC-Conc.html#t:ThreadStatus">ThreadStatus</a></p></div><h1 id="g:2">Waiting </h1><div class="top"><p class="src"><a name="v:threadDelay" class="def">threadDelay</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Suspends the current thread for a given number of microseconds (GHC only). </p><p>There is no guarantee that the thread will be rescheduled promptly when the delay has expired, but the thread will never continue to run <em>earlier</em> than specified. </p></div></div><div class="top"><p class="src"><a name="v:registerDelay" class="def">registerDelay</a> :: <a href="Data-Int.html#t:Int">Int</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> <a href="Data-Bool.html#t:Bool">Bool</a>)</p><div class="doc"><p>Set the value of returned TVar to True after a given number of microseconds. The caveats associated with threadDelay also apply. </p></div></div><div class="top"><p class="src"><a name="v:threadWaitRead" class="def">threadWaitRead</a> :: <a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Block the current thread until data is available to read on the given file descriptor (GHC only). </p><p>This will throw an <code>IOError</code> if the file descriptor was closed while this thread was blocked. To safely close a file descriptor that has been used with <code><a href="GHC-Conc.html#v:threadWaitRead">threadWaitRead</a></code>, use <code><a href="GHC-Conc.html#v:closeFdWith">closeFdWith</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:threadWaitWrite" class="def">threadWaitWrite</a> :: <a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Block the current thread until data can be written to the given file descriptor (GHC only). </p><p>This will throw an <code>IOError</code> if the file descriptor was closed while this thread was blocked. To safely close a file descriptor that has been used with <code><a href="GHC-Conc.html#v:threadWaitWrite">threadWaitWrite</a></code>, use <code><a href="GHC-Conc.html#v:closeFdWith">closeFdWith</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:closeFdWith" class="def">closeFdWith</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="System-Posix-Types.html#t:Fd">Fd</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>)</td><td class="doc"><p>Low-level action that performs the real close. </p></td></tr><tr><td class="src">-> <a href="System-Posix-Types.html#t:Fd">Fd</a></td><td class="doc"><p>File descriptor to close. </p></td></tr><tr><td class="src">-> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Close a file descriptor in a concurrency-safe way (GHC only). If you are using <code><a href="GHC-Conc.html#v:threadWaitRead">threadWaitRead</a></code> or <code><a href="GHC-Conc.html#v:threadWaitWrite">threadWaitWrite</a></code> to perform blocking I/O, you <em>must</em> use this function to close file descriptors, or blocked threads may not be woken. </p><p>Any threads that are blocked on the file descriptor via <code><a href="GHC-Conc.html#v:threadWaitRead">threadWaitRead</a></code> or <code><a href="GHC-Conc.html#v:threadWaitWrite">threadWaitWrite</a></code> will be unblocked by having IO exceptions thrown. </p></div></div><h1 id="g:3">TVars </h1><div class="top"><p class="src"><span class="keyword">newtype</span> <a name="t:STM" class="def">STM</a> a </p><div class="doc"><p>A monad supporting atomic memory transactions. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:STM" class="def">STM</a> (<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:State-35-">State#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a> -> (#<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:State-35-">State#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a>, a#))</td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><p id="control.i:STM" class="caption collapser" onclick="toggleSection('i:STM')">Instances</p><div id="section.i:STM" class="show"><table><tr><td class="src"><a href="Control-Monad.html#t:Monad">Monad</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad.html#t:Functor">Functor</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable.html#t:Typeable1">Typeable1</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Monad.html#t:MonadPlus">MonadPlus</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Applicative.html#t:Applicative">Applicative</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Applicative.html#t:Alternative">Alternative</a> <a href="GHC-Conc.html#t:STM">STM</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:atomically" class="def">atomically</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Perform a series of STM actions atomically. </p><p>You cannot use <code><a href="GHC-Conc.html#v:atomically">atomically</a></code> inside an <code><a href="System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></code> or <code><a href="System-IO-Unsafe.html#v:unsafeInterleaveIO">unsafeInterleaveIO</a></code>. Any attempt to do so will result in a runtime error. (Reason: allowing this would effectively allow a transaction inside a transaction, depending on exactly when the thunk is evaluated.) </p><p>However, see <code><a href="GHC-Conc.html#v:newTVarIO">newTVarIO</a></code>, which can be called inside <code><a href="System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></code>, and which allows top-level TVars to be allocated. </p></div></div><div class="top"><p class="src"><a name="v:retry" class="def">retry</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>Retry execution of the current memory transaction because it has seen values in TVars which mean that it should not continue (e.g. the TVars represent a shared buffer that is now empty). The implementation may block the thread until one of the TVars that it has read from has been udpated. (GHC only) </p></div></div><div class="top"><p class="src"><a name="v:orElse" class="def">orElse</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>Compose two alternative STM actions (GHC only). If the first action completes without retrying then it forms the result of the orElse. Otherwise, if the first action retries, then the second action is tried in its place. If both actions retry then the orElse as a whole retries. </p></div></div><div class="top"><p class="src"><a name="v:throwSTM" class="def">throwSTM</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>A variant of <code><a href="Control-Exception-Base.html#v:throw">throw</a></code> that can only be used within the <code><a href="GHC-Conc.html#t:STM">STM</a></code> monad. </p><p>Throwing an exception in <code>STM</code> aborts the transaction and propagates the exception. </p><p>Although <code><a href="GHC-Conc.html#v:throwSTM">throwSTM</a></code> has a type that is an instance of the type of <code><a href="Control-Exception-Base.html#v:throw">throw</a></code>, the two functions are subtly different: </p><pre> throw e `seq` x ===> throw e throwSTM e `seq` x ===> x </pre><p>The first example will cause the exception <code>e</code> to be raised, whereas the second one won't. In fact, <code><a href="GHC-Conc.html#v:throwSTM">throwSTM</a></code> will only cause an exception to be raised when it is used within the <code><a href="GHC-Conc.html#t:STM">STM</a></code> monad. The <code><a href="GHC-Conc.html#v:throwSTM">throwSTM</a></code> variant should be used in preference to <code><a href="Control-Exception-Base.html#v:throw">throw</a></code> to raise an exception within the <code><a href="GHC-Conc.html#t:STM">STM</a></code> monad because it guarantees ordering with respect to other <code><a href="GHC-Conc.html#t:STM">STM</a></code> operations, whereas <code><a href="Control-Exception-Base.html#v:throw">throw</a></code> does not. </p></div></div><div class="top"><p class="src"><a name="v:catchSTM" class="def">catchSTM</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => <a href="GHC-Conc.html#t:STM">STM</a> a -> (e -> <a href="GHC-Conc.html#t:STM">STM</a> a) -> <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>Exception handling within STM actions. </p></div></div><div class="top"><p class="src"><a name="v:alwaysSucceeds" class="def">alwaysSucceeds</a> :: <a href="GHC-Conc.html#t:STM">STM</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>alwaysSucceeds adds a new invariant that must be true when passed to alwaysSucceeds, at the end of the current transaction, and at the end of every subsequent transaction. If it fails at any of those points then the transaction violating it is aborted and the exception raised by the invariant is propagated. </p></div></div><div class="top"><p class="src"><a name="v:always" class="def">always</a> :: <a href="GHC-Conc.html#t:STM">STM</a> <a href="Data-Bool.html#t:Bool">Bool</a> -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>always is a variant of alwaysSucceeds in which the invariant is expressed as an STM Bool action that must return True. Returning False or raising an exception are both treated as invariant failures. </p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:TVar" class="def">TVar</a> a </p><div class="doc"><p>Shared memory locations that support atomic memory transactions. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:TVar" class="def">TVar</a> (<a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:TVar-35-">TVar#</a> <a href="Control-Monad-ST.html#t:RealWorld">RealWorld</a> a)</td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><p id="control.i:TVar" class="caption collapser" onclick="toggleSection('i:TVar')">Instances</p><div id="section.i:TVar" class="show"><table><tr><td class="src"><a href="Data-Typeable.html#t:Typeable1">Typeable1</a> <a href="GHC-Conc.html#t:TVar">TVar</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> a)</td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:newTVar" class="def">newTVar</a> :: a -> <a href="GHC-Conc.html#t:STM">STM</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> a)</p><div class="doc"><p>Create a new TVar holding a value supplied </p></div></div><div class="top"><p class="src"><a name="v:newTVarIO" class="def">newTVarIO</a> :: a -> <a href="System-IO.html#t:IO">IO</a> (<a href="GHC-Conc.html#t:TVar">TVar</a> a)</p><div class="doc"><p><code>IO</code> version of <code><a href="GHC-Conc.html#v:newTVar">newTVar</a></code>. This is useful for creating top-level <code><a href="GHC-Conc.html#t:TVar">TVar</a></code>s using <code>System.IO.Unsafe.unsafePerformIO</code>, because using <code><a href="GHC-Conc.html#v:atomically">atomically</a></code> inside <code>System.IO.Unsafe.unsafePerformIO</code> isn't possible. </p></div></div><div class="top"><p class="src"><a name="v:readTVar" class="def">readTVar</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>Return the current value stored in a TVar </p></div></div><div class="top"><p class="src"><a name="v:readTVarIO" class="def">readTVarIO</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Return the current value stored in a TVar. This is equivalent to </p><pre> readTVarIO = atomically . readTVar </pre><p>but works much faster, because it doesn't perform a complete transaction, it just reads the current value of the <code><a href="GHC-Conc.html#t:TVar">TVar</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:writeTVar" class="def">writeTVar</a> :: <a href="GHC-Conc.html#t:TVar">TVar</a> a -> a -> <a href="GHC-Conc.html#t:STM">STM</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p><div class="doc"><p>Write the supplied value into a TVar </p></div></div><div class="top"><p class="src"><a name="v:unsafeIOToSTM" class="def">unsafeIOToSTM</a> :: <a href="System-IO.html#t:IO">IO</a> a -> <a href="GHC-Conc.html#t:STM">STM</a> a</p><div class="doc"><p>Unsafely performs IO in the STM monad. Beware: this is a highly dangerous thing to do. </p><ul><li> The STM implementation will often run transactions multiple times, so you need to be prepared for this if your IO has any side effects. </li><li> The STM implementation will abort transactions that are known to be invalid and need to be restarted. This may happen in the middle of <code><a href="GHC-Conc.html#v:unsafeIOToSTM">unsafeIOToSTM</a></code>, so make sure you don't acquire any resources that need releasing (exception handlers are ignored when aborting the transaction). That includes doing any IO using Handles, for example. Getting this wrong will probably lead to random deadlocks. </li><li> The transaction may have seen an inconsistent view of memory when the IO runs. Invariants that you expect to be true throughout your program may not be true inside a transaction, due to the way transactions are implemented. Normally this wouldn't be visible to the programmer, but using <code><a href="GHC-Conc.html#v:unsafeIOToSTM">unsafeIOToSTM</a></code> can expose it. </li></ul></div></div><h1 id="g:4">Miscellaneous </h1><div class="top"><p class="src"><a name="v:withMVar" class="def">withMVar</a> :: <a href="Control-Concurrent-MVar.html#t:MVar">MVar</a> a -> (a -> <a href="System-IO.html#t:IO">IO</a> b) -> <a href="System-IO.html#t:IO">IO</a> b</p></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:Signal" class="def">Signal</a> = <a href="Foreign-C-Types.html#t:CInt">CInt</a></p></div><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:HandlerFun" class="def">HandlerFun</a> = <a href="Foreign-ForeignPtr.html#t:ForeignPtr">ForeignPtr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:setHandler" class="def">setHandler</a> :: <a href="GHC-Conc.html#t:Signal">Signal</a> -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> (<a href="GHC-Conc.html#t:HandlerFun">HandlerFun</a>, <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a>) -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Maybe.html#t:Maybe">Maybe</a> (<a href="GHC-Conc.html#t:HandlerFun">HandlerFun</a>, <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a>))</p></div><div class="top"><p class="src"><a name="v:runHandlers" class="def">runHandlers</a> :: <a href="Foreign-ForeignPtr.html#t:ForeignPtr">ForeignPtr</a> <a href="Data-Word.html#t:Word8">Word8</a> -> <a href="GHC-Conc.html#t:Signal">Signal</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:ensureIOManagerIsRunning" class="def">ensureIOManagerIsRunning</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:setUncaughtExceptionHandler" class="def">setUncaughtExceptionHandler</a> :: (<a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:getUncaughtExceptionHandler" class="def">getUncaughtExceptionHandler</a> :: <a href="System-IO.html#t:IO">IO</a> (<a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a>)</p></div><div class="top"><p class="src"><a name="v:reportError" class="def">reportError</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div><div class="top"><p class="src"><a name="v:reportStackOverflow" class="def">reportStackOverflow</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Unit.html#t:-40--41-">()</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.9.2</p></div></body></html>