Proposal: Add Control.Concurrent.forkIOWithUnmask, deprecate forkIOUnmasked

Bas van Dijk v.dijk.bas at gmail.com
Wed Dec 22 13:27:05 CET 2010


On Wed, Dec 22, 2010 at 11:50 AM, Simon Marlow <marlowsd at gmail.com> wrote:
> This proposal is to replace forkIOUnmasked with forkIOWithUnmask:

+1

forkIOUnmasked was also difficult to wrap in my threads[1] library. I
had to use the deprecated block and unblock operations to implement
it:

{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-} -- For block and unblock
forkIOUnmasked ∷ IO α → IO (ThreadId, IO (Result α))
forkIOUnmasked a = do
  res ← newEmptyMVar
  tid ← block $ Control.Concurrent.forkIO $ try (unblock a) >>= putMVar res
  return (tid, readMVar res)

I don't need to use deprecated functions to wrap forkIOWithUnmask:

forkIOWithUnmask ∷ ((∀ α. IO α → IO α) → IO α) → IO (ThreadId, IO (Result α))
forkIOWithUnmask io = do
  res ← newEmptyMVar
  tid ← mask_ $ Control.Concurrent.forkIOWithUnmask $ \restore →
                  try (io restore) >>= putMVar res
  return (tid, readMVar res)

Regards,

Bas

[1] http://hackage.haskell.org/packages/archive/threads/0.4/doc/html/Control-Concurrent-Thread.html#v:forkIOUnmasked



More information about the Libraries mailing list