Asynchronous Exceptions
Simon Marlow
simonmar@microsoft.com
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
>=20
> finally :: IO a -> IO b -> IO s
>=20
> finally a b =3D=20
> block (do {
> r <- catch (unblock a) (\e -> do { b; throw e });
> b;
> return r; })
>=20
> Now suppose we have
>=20
> finally (putStrLn "Test Started") (putStrLn "Test Terminated")
>=20
> 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
>=20
> Test Started
> Test Term
>=20
> 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.
Cheers,
Simon