[Haskell-cafe] Problems with Network/MVar

Gregory Collins greg at gregorycollins.net
Tue Apr 1 12:05:36 UTC 2014


On Tue, Apr 1, 2014 at 1:35 PM, Pierre-Étienne Meunier <
pierreetienne.meunier at gmail.com> wrote:

> Is this the same as using “bracket accept hClose $ blabla” (modulo correct
> types)?


Sort of (and you could turn this pattern into a similar combinator), except
here you want to accept the socket and hand it off to a child thread. In
order to make that pattern safe you have to use mask:

    foo = mask $ \unmask -> do
        (s, a, _) <- unmask $ accept sock
        -- here async exceptions are blocked which gives you time to
install a signal
        -- handler, you only unmask exceptions once the handler is installed
        forkIOWithUnmask $ \restore -> ((restore $ reply state s a) `catch`
handler) `finally` (cleanup s a)

-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140401/48886020/attachment.html>


More information about the Haskell-Cafe mailing list