<div dir="ltr"><div>The documentation of withMVar (in Control.Concurrent.MVar module of base package) says:</div><div><br></div><div><pre><span class="gmail-hs-comment">{-|
<a name="line-175"></a> 'withMVar' is an exception-safe wrapper for operating on the contents
<a name="line-176"></a> of an 'MVar'. This operation is exception-safe: it will replace the
<a name="line-177"></a> original contents of the 'MVar' if an exception is raised (see
<a name="line-178"></a> "Control.Exception"). However, it is only atomic if there are no
<a name="line-179"></a> other producers for this 'MVar'.
<a name="line-180"></a>-}</span>
<a name="line-181"></a><a name="line-184"></a><span class="gmail-hs-definition">withMVar</span> <span class="gmail-hs-keyglyph">::</span> <span class="gmail-hs-conid">MVar</span> <span class="gmail-hs-varid">a</span> <span class="gmail-hs-keyglyph">-></span> <span class="gmail-hs-layout">(</span><span class="gmail-hs-varid">a</span> <span class="gmail-hs-keyglyph">-></span> <span class="gmail-hs-conid">IO</span> <span class="gmail-hs-varid">b</span><span class="gmail-hs-layout">)</span> <span class="gmail-hs-keyglyph">-></span> <span class="gmail-hs-conid">IO</span> <span class="gmail-hs-varid">b</span>
<a name="line-185"></a><span class="gmail-hs-definition">withMVar</span> <span class="gmail-hs-varid">m</span> <span class="gmail-hs-varid">io</span> <span class="gmail-hs-keyglyph">=</span>
<a name="line-186"></a> <span class="gmail-hs-varid">mask</span> <span class="gmail-hs-varop">$</span> <span class="gmail-hs-keyglyph">\</span><span class="gmail-hs-varid">restore</span> <span class="gmail-hs-keyglyph">-></span> <span class="gmail-hs-keyword">do</span>
<a name="line-187"></a> <span class="gmail-hs-varid">a</span> <span class="gmail-hs-keyglyph"><-</span> <span class="gmail-hs-varid">takeMVar</span> <span class="gmail-hs-varid">m</span>
<a name="line-188"></a> <span class="gmail-hs-varid">b</span> <span class="gmail-hs-keyglyph"><-</span> <span class="gmail-hs-varid">restore</span> <span class="gmail-hs-layout">(</span><span class="gmail-hs-varid">io</span> <span class="gmail-hs-varid">a</span><span class="gmail-hs-layout">)</span> <span class="gmail-hs-varop">`onException`</span> <span class="gmail-hs-varid">putMVar</span> <span class="gmail-hs-varid">m</span> <span class="gmail-hs-varid">a</span>
<a name="line-189"></a> <span class="gmail-hs-varid">putMVar</span> <span class="gmail-hs-varid">m</span> <span class="gmail-hs-varid">a</span>
<a name="line-190"></a> <span class="gmail-hs-varid">return</span> <span class="gmail-hs-varid">b<br><br></span></pre><pre><span style="font-family:arial,sans-serif"><span class="gmail-hs-varid">Can someone shed some light on what is meant by the statement - <br>"<span class="gmail-hs-comment">However, it is only atomic if there are no other producers for this 'MVar'."?<br></span></span></span></pre><pre><span style="font-family:arial,sans-serif"><span class="gmail-hs-varid"><span class="gmail-hs-comment">I hope this is the right mailing list for this question.<br></span></span></span></pre><pre><span style="font-family:arial,sans-serif"><span class="gmail-hs-varid"><span class="gmail-hs-comment">Thanks,</span></span></span><span class="gmail-hs-varid"><span class="gmail-hs-comment"><span style="font-family:arial,sans-serif"><br>Harendra</span><br></span></span></pre></div></div>