#4810: Versions of bracket without masking acquire action
---------------------------------+------------------------------------------
Reporter: mitar | Owner:
Type: proposal | Status: new
Priority: normal | Milestone:
Component: libraries/base | Version: 7.0.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by mitar):
I agree with you.
As I see there are two possibilities. We can add a version of `bracket`
where actions gets as an argument `restore` function. So that they can
`restore` it inside, for example they can have internally more `bracket`s,
which make sure things are not acquired if exception is raised, but that
exception can still be raised in a lengthy acquire.
The other, which I opted for above, is that we unmask acquire and then
user can call `mask` immediately at the beginning of the acquire action,
thus having a `restore` for use somewhere later. This short period of non-
masked state is not a problem as nothing has yet been really acquired at
the beginning of the acquire action.
My code where I require something like this is (simplified):
{{{
bracketOnErrorUnmasked createThread killThread doSomethingWithThread
createThread = mask $ \restore -> do
-- do some preparations
forkIO $ bracket prepareThread cleanupThreadAndFillMVar (restore
doThreadAction)
}}}
In original code there is then also a `Chan` for interaction with this
created thread in `doSomethingWithThread`, but this is not important.
`bracketOnErrorUnmasked` is a version of `bracketOnError` without masked
acquire action.
`forkIOUnmasked` does not help here because then there is a short period
of time when `cleanupThreadAndFillMVar` will not be called (before
internal `bracket` is initialized) so my program could hang waiting for
`MVar` from a thread. And I want `doThreadAction` to be unmasked as
otherwise thread is killable only in interruptible actions.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4810#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs