[Haskell-cafe] Asynchronous exceptions and the RealWorld

Yang hehx0sk02 at sneakemail.com
Thu Nov 15 17:29:08 EST 2007

- I want to set timeouts on various IO operations in an existing 
library, ftphs. However, even if I wrap every call in `block`, it's 
unclear whether ftphs has been coded to deal with asynchronous 
exceptions, or whether state could be rendered inconsistent. Is there 
any solution for this aside from auditing/changing ftphs?

- I can't find any documentation on which calls are (either directly or 
indirectly, or parametrically) "interruptible operations" (to use the 
term from the Async Exceptions paper). For instance, I experimentally 
determined that hPutStrLn on a socket is *not*. Does such documentation 
exist anywhere? Furthermore, is there any way to embed this information 
in the type system, so that Haskellers don't produce 
async-exception-unaware code? (Effectively, introducing checked interrupts?)

- The above finding of hPutStrLn (as an example) is somewhat surprising, 
since the socket buffer may be full, causing the call to block 
indefinitely. We can unblock that call, but unless there's a way to 
atomically reinstate the block and save the result of the computation 
(the unit value), this effectively makes it impossible to determine 
whether the hPutStrLn returned. (Admittedly, this is a contrived 
example, since whether a call to hPutStrLn returns is usually not a 
useful result - but this is the first thing I tried, and I'm guessing 
there are more such IO operations that actually yield useful results.)

- Are there any higher-level concurrency libraries that actually tackle 
these hand-in-hand issues (safe asynchronous interruptible IO, 
two-phase-commit to prevent dropping results, choice, etc.)? I tried 
searching for a while, coming up with PiMonad, HAppS.Util, 
MissingH.Threads.Timeout, but none of them really address these issues. 
Perhaps this is just impossible in Concurrent Haskell, and one would 
need to resort to the sure-fire home-rolled solution using delimited 
continuations and cooperative scheduling for any serious concurrency 
abstractions for systems programming.

Thanks in advance for any answers!

More information about the Haskell-Cafe mailing list