RE: Asynchronous Exceptions
Can someone help me understand how this works? I've been reading the paper "Asynchronous Exceptions in Haskell". This gives a combinator
finally :: IO a -> IO b -> IO s
finally a b = 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 therefore can be interrupted. So the interrupt could occur 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 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. 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
Hello! On Fri, Nov 23, 2001 at 09:38:35AM -0000, Simon Marlow wrote:
[...]
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.
But even things like putStr can block for an unbounded amount of time. E.g. stdout is a pipe and the reader just doesn't read it for n hours (n unknown), etc. Kind regards, Hannah.
participants (2)
-
Hannah Schroeter -
Simon Marlow