#8818 closed feature request (fixed)

Add withMVarMasked

Reported by: hvr Owned by: hvr
Priority: normal Milestone: 7.8.1
Component: libraries/base Version:
Keywords: Cc: simonmar
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

We already have modifyMVarMasked and modifyMVarMasked_, and so I propose to add

{-|
  Like 'withMVar', but the @IO@ action in the second argument is executed
  with asynchronous exceptions masked.

  /Since: 4.7.0.0/
-}
{-# INLINE withMVarMasked_ #-}
withMVarMasked :: MVar a -> (a -> IO b) -> IO b
withMVarMasked m io =
  mask_ $ do
    a <- takeMVar m
    b <- io a `onException` putMVar m a
    putMVar m a
    return b

any arguments against this addition?

Change History (2)

comment:1 Changed 17 months ago by Herbert Valerio Riedel <hvr@…>

In 2d5471cd3ee42406042a030424a1a83308a170fa/base:

Add `withMVarMasked` (re #8818)

Like `withMVar`, but the @IO@ action in the second argument is executed
with asynchronous exceptions masked. This completes the `MVar` API,
which already contained `modifyMVarMasked` and `modifyMVarMasked_`.

Signed-off-by: Herbert Valerio Riedel <[email protected]>

comment:2 Changed 17 months ago by hvr

  • Milestone changed from 7.10.1 to 7.8.1
  • Resolution set to fixed
  • Status changed from new to closed

I went ahead with this (after simonmar confirmed to me on IRC this addition made sense).

Also, this has been merged in the ghc-7.8 branch via [a91d68221ca30/base]

Note: See TracTickets for help on using tickets.