<!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.5.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><tr><th>Safe Haskell</th><td>Unsafe</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-Tuple.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-Tuple.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:forkIOWithUnmask">forkIOWithUnmask</a> :: ((<span class="keyword">forall</span> a. <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.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:forkOn">forkOn</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-Tuple.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-Tuple.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-Tuple.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:forkOnWithUnmask">forkOnWithUnmask</a> :: <a href="Data-Int.html#t:Int">Int</a> -> ((<span class="keyword">forall</span> a. <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.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:getNumCapabilities">getNumCapabilities</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:setNumCapabilities">setNumCapabilities</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-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:getNumProcessors">getNumProcessors</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: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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-String.html#t:String">String</a> -> <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"><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:threadCapability">threadCapability</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Int.html#t:Int">Int</a>, <a href="Data-Bool.html#t:Bool">Bool</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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-Safe.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-Safe.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-Tuple.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-Tuple.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-Safe.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-Tuple.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-Safe.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-Tuple.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-Safe.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-Tuple.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-Tuple.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-Tuple.html#t:-40--41-">()</a>) -> <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: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-Tuple.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-Tuple.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-Tuple.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-Internal.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-Tuple.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><a href="Control-Concurrent.html#v:forkOS">forkOS</a></code> instead. </p><p>GHC note: the new thread inherits the <em>masked</em> state of the parent (see <code><a href="Control-Exception.html#v:mask">mask</a></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. </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-Tuple.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>This function is deprecated; use <code>forkIOWIthUnmask</code> instead </p></div></div><div class="top"><p class="src"><a name="v:forkIOWithUnmask" class="def">forkIOWithUnmask</a> :: ((<span class="keyword">forall</span> a. <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.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 passed a function that can be used to unmask asynchronous exceptions. This function is typically used in the following way </p><pre> ... mask_ $ forkIOWithUnmask $ \unmask -> catch (unmask ...) handler </pre><p>so that the exception handler in the child thread is established with asynchronous exceptions masked, meanwhile the main body of the child thread is executed in the unmasked state. </p><p>Note that the unmask function passed to the child thread should only be used in that thread; the behaviour is undefined if it is invoked in a different thread. </p></div></div><div class="top"><p class="src"><a name="v:forkOn" class="def">forkOn</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-Tuple.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 processor the thread should run. 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:forkOn">forkOn</a></code> will stay on the same processor for its entire lifetime (<code><a href="GHC-Conc.html#v:forkIO">forkIO</a></code> threads can migrate between processors according to the scheduling policy). <code><a href="GHC-Conc.html#v:forkOn">forkOn</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 a <em>capability number</em> (see <code><a href="GHC-Conc.html#v:getNumCapabilities">getNumCapabilities</a></code>). Typically capabilities correspond to physical processors, but the exact behaviour is implementation-dependent. The value passed to <code><a href="GHC-Conc.html#v:forkOn">forkOn</a></code> is interpreted modulo the total number of capabilities as returned by <code><a href="GHC-Conc.html#v:getNumCapabilities">getNumCapabilities</a></code>. </p><p>GHC note: the number of capabilities is specified by the <code>+RTS -N</code> option when the program is started. Capabilities can be fixed to actual processor cores with <code>+RTS -qa</code> if the underlying operating system supports that, although in practice this is usually unnecessary (and may actually degrade perforamnce in some cases - experimentation is recommended). </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-Tuple.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>This function is deprecated; use <code><a href="GHC-Conc.html#v:forkOn">forkOn</a></code> instead </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-Tuple.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>This function is deprecated; use <code>forkOnWIthUnmask</code> instead </p></div></div><div class="top"><p class="src"><a name="v:forkOnWithUnmask" class="def">forkOnWithUnmask</a> :: <a href="Data-Int.html#t:Int">Int</a> -> ((<span class="keyword">forall</span> a. <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.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:forkIOWithUnmask">forkIOWithUnmask</a></code>, but the child thread is pinned to the given CPU, as with <code><a href="GHC-Conc.html#v:forkOn">forkOn</a></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 processor cores on the machine. </p><p>Strictly speaking it is better to use <code><a href="GHC-Conc.html#v:getNumCapabilities">getNumCapabilities</a></code>, because the number of capabilities might vary at runtime. </p></div></div><div class="top"><p class="src"><a name="v:getNumCapabilities" class="def">getNumCapabilities</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 Haskell threads that can run truly simultaneously (on separate physical processors) at any given time. The number passed to <code><a href="GHC-Conc.html#v:forkOn">forkOn</a></code> is interpreted modulo this value. </p><p>An implementation in which Haskell threads are mapped directly to OS threads might return the number of physical processor cores in the machine, and <code><a href="GHC-Conc.html#v:forkOn">forkOn</a></code> would be implemented using the OS's affinity facilities. An implementation that schedules Haskell threads onto a smaller number of OS threads (like GHC) would return the number of such OS threads that can be running simultaneously. </p><p>GHC notes: this returns the number passed as the argument to the <code>+RTS -N</code> flag. In current implementations, the value is fixed when the program starts and never changes, but it is possible that in the future the number of capabilities might vary at runtime. </p></div></div><div class="top"><p class="src"><a name="v:setNumCapabilities" class="def">setNumCapabilities</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-Tuple.html#t:-40--41-">()</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. </p><p>GHC notes: in the current implementation, the value may only be <em>increased</em>, not decreased, by calling <code><a href="GHC-Conc.html#v:setNumCapabilities">setNumCapabilities</a></code>. The initial value is given by the <code>+RTS -N</code> flag, and the current value may be obtained using <code><a href="GHC-Conc.html#v:getNumCapabilities">getNumCapabilities</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:getNumProcessors" class="def">getNumProcessors</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Int.html#t:Int">Int</a></p></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-Tuple.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-Tuple.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-Tuple.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. However, in GHC a foreign call can be annotated as <code>interruptible</code>, in which case a <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> will cause the RTS to attempt to cause the call to return; see the GHC documentation for more details. </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>If the target of <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is the calling thread, then the behaviour is the same as <code><a href="Control-Exception.html#v:throwIO">throwIO</a></code>, except that the exception is thrown as an asynchronous exception. This means that if there is an enclosing pure computation, which would be the case if the current IO operation is inside <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>, that computation is not permanently replaced by the exception, but is suspended as if it had received an asynchronous exception. </p><p>Note that if <code><a href="GHC-Conc.html#v:throwTo">throwTo</a></code> is called with the current thread as the target, the exception will be thrown even if the thread is currently inside <code><a href="Control-Exception-Base.html#v:mask">mask</a></code> or <code><a href="Control-Exception-Base.html#v:uninterruptibleMask">uninterruptibleMask</a></code>. </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-Tuple.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-Tuple.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-String.html#t:String">String</a> -> <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><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><div class="top"><p class="src"><a name="v:threadCapability" class="def">threadCapability</a> :: <a href="GHC-Conc.html#t:ThreadId">ThreadId</a> -> <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Int.html#t:Int">Int</a>, <a href="Data-Bool.html#t:Bool">Bool</a>)</p><div class="doc"><p>returns the number of the capability on which the thread is currently running, and a boolean indicating whether the thread is locked to that capability or not. A thread is locked to a capability if it was created with <code>forkOn</code>. </p></div></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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-Tuple.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-Safe.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-Safe.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-Internal.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-Tuple.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-Tuple.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-Safe.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-Internal.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><a href="System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></code>, because using <code><a href="GHC-Conc.html#v:atomically">atomically</a></code> inside <code><a href="System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></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-Tuple.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-Safe.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-Tuple.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-Safe.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-Tuple.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-Tuple.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-Tuple.html#t:-40--41-">()</a>) -> <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><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-Tuple.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-Tuple.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-Tuple.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.11.0</p></div></body></html>