Proposal: Add Control.Concurrent.forkIOWithUnmask, deprecate forkIOUnmasked

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

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


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

{-# 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)




More information about the Libraries mailing list