<div dir="ltr">Michael Walker explained quite well why that's reasonable. What seems much *less* reasonable is that the function masks exceptions right from the start and all the way to the end. I don't see any reason to mask until after calling getSystemEventManager_, or to remain masked after taking the MVar.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 17, 2019 at 5:17 PM Andrew Martin <<a href="mailto:andrew.thaddeus@gmail.com">andrew.thaddeus@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The definition of threadWait is:</div><div><pre style="color:rgb(0,0,0)"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">threadWait</span> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">::</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Internal.html#Event" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-type" style="color:rgb(95,95,175)">Event</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">-></span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/System.Posix.Types.html#Fd" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-type" style="color:rgb(95,95,175)">Fd</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">-></span> <span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-type" style="color:rgb(95,95,175)">IO</span> <span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">(</span><span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">)</span>
<a name="m_5130185092482346118_line-115"></a><a name="m_5130185092482346118_threadWait"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#threadWait" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">threadWait</span></a> <a name="m_5130185092482346118_local-6989586621679365266"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365266" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">evt</span></a> <a name="m_5130185092482346118_local-6989586621679365267"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365267" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">fd</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">=</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.IO.html#mask_" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">mask_</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Base.html#%24" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-operator gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(211,54,130)">$</span></a> <span class="gmail-m_5130185092482346118gmail-hs-keyword" style="color:rgb(175,0,95)">do</span>
<a name="m_5130185092482346118_line-116"></a> <a name="m_5130185092482346118_local-6989586621679365268"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365268" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">m</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)"><-</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.MVar.html#newEmptyMVar" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">newEmptyMVar</span></a>
<a name="m_5130185092482346118_line-117"></a> <a name="m_5130185092482346118_local-6989586621679365269"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365269" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">mgr</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)"><-</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#getSystemEventManager_" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">getSystemEventManager_</span></a>
<a name="m_5130185092482346118_line-118"></a> <a name="m_5130185092482346118_local-6989586621679365271"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365271" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">reg</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)"><-</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Manager.html#registerFd" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">registerFd</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365269" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">mgr</span></a> <span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">(</span><span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">\</span><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">_</span> <a name="m_5130185092482346118_local-6989586621679365270"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365270" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">e</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)">-></span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.MVar.html#putMVar" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">putMVar</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365268" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">m</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365270" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">e</span></a><span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">)</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365267" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">fd</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365266" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">evt</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Internal.html#OneShot" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">M.OneShot</span></a>
<a name="m_5130185092482346118_line-119"></a> <a name="m_5130185092482346118_local-6989586621679365272"></a><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365272" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier" style="color:rgb(7,54,66)">evt'</span></a> <span class="gmail-m_5130185092482346118gmail-hs-glyph" style="color:rgb(220,50,47)"><-</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.MVar.html#takeMVar" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">takeMVar</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365268" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">m</span></a> <span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">`</span><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.IO.html#onException" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">onException</span></a><span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">`</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Manager.html#unregisterFd_" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">unregisterFd_</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365269" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">mgr</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365271" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">reg</span></a>
<a name="m_5130185092482346118_line-120"></a> <span class="gmail-m_5130185092482346118gmail-hs-keyword" style="color:rgb(175,0,95)">if</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Thread.html#local-6989586621679365272" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">evt'</span></a> <span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">`</span><a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Internal.html#eventIs" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">eventIs</span></a><span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">`</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Event.Internal.html#evtClose" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">evtClose</span></a>
<a name="m_5130185092482346118_line-121"></a> <span class="gmail-m_5130185092482346118gmail-hs-keyword" style="color:rgb(175,0,95)">then</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.IO.Exception.html#ioError" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">ioError</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Base.html#%24" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-operator gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(211,54,130)">$</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/Foreign.C.Error.html#errnoToIOError" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">errnoToIOError</span></a> <span class="gmail-m_5130185092482346118gmail-hs-string" style="color:rgb(203,75,22)">"threadWait"</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/Foreign.C.Error.html#eBADF" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">eBADF</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Maybe.html#Nothing" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">Nothing</span></a> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Maybe.html#Nothing" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">Nothing</span></a>
<a name="m_5130185092482346118_line-122"></a> <span class="gmail-m_5130185092482346118gmail-hs-keyword" style="color:rgb(175,0,95)">else</span> <a href="http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Base.html#return" class="gmail-m_5130185092482346118gmail-" style="text-decoration-line:none;border-bottom:1px solid rgb(238,232,213)" target="_blank"><span class="gmail-m_5130185092482346118gmail-hs-identifier gmail-m_5130185092482346118gmail-hs-var" style="color:rgb(7,54,66)">return</span></a> <span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">(</span><span class="gmail-m_5130185092482346118gmail-hs-special" style="color:rgb(220,50,47)">)</span>
</pre>Although the entire function has asynchronous exceptions masked, the call to takeMVar uses onException to deal with the possibility of an exception. According to the docs in Control.Concurrent, takeMVar can throw exceptions. But my understand (which may be wrong) is that the only exception this could throw would be something like BlockedIndefinitelyOnMVar, which I don't believe can happen here.</div><div><br></div><div>-- <br><div dir="ltr" class="gmail-m_5130185092482346118gmail_signature">-Andrew Thaddeus Martin</div></div></div>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>