title: What is the purpose of the extra result parameter of atomicModifyIORef?
body: <p>The signature of <code>modifyIORef</code> is straightforward enough:</p>
  
  <pre><code>modifyIORef :: IORef a -&gt; (a -&gt; a) -&gt; IO ()
  </code></pre>
  
  <p>Unfortunately, this is not thread safe. There is an alternative that adresses this issue:</p>
  
  <pre><code>atomicModifyIORef :: IORef a -&gt; (a -&gt; (a,b)) -&gt; IO b
  </code></pre>
  
  <p>What exactly are the differences between these two functions? How am I supposed to use the <code>b</code> parameter when modifying an <code>IORef</code> that might be read from another thread?</p>