Asynchronous Exceptions

Simon Marlow
Fri, 23 Nov 2001 09:38:35 -0000

> Can someone help me understand how this works? I've been=20
> reading the paper "Asynchronous Exceptions in Haskell". This=20
> gives a combinator
> finally :: IO a -> IO b -> IO s
> finally a b =3D=20
>    block (do {
>       r <- catch (unblock a) (\e -> do { b; throw e });
>       b;
>       return r; })
> Now suppose we have
> finally (putStrLn "Test Started") (putStrLn "Test Terminated")
> then looking at the semantics, putStrLn can become stuck and=20
> therefore can be interrupted. So the interrupt could occur=20
> whilst "Test Terminated" is being output and we could end up with
> Test Started
> Test Term
> Is this what could happen? If so, is there a way of making=20
> sure that "Test Terminated" is output?

Yes, that's correct.  putStrLn is interruptible, so you can't force it
to run to completion - to do so would introduce a possible deadlock. =20

However, I agree that sometimes you really want to be able to do this,
so perhaps we need another form of 'block' which doesn't allow *any*
exceptions to be delivered, for those times when you know that the time
spent waiting in an interruptible operation is going to be bounded.