[Haskell-cafe] How to make asynchronous I/O composable and safe?
joeyadams3.14159 at gmail.com
Wed Jan 18 04:37:24 CET 2012
On Tue, Jan 17, 2012 at 3:20 PM, David Barbour <dmbarbour at gmail.com> wrote:
> I'd say use of asynchronous exceptions should be a last resort. ...
I agree. However, network libraries in Haskell (e.g. Handle,
Network.TLS) generally don't provide the primitives needed to do that
on the receiving end. For example, if a thread is blocked on hGetBuf,
it cannot also wait on a signal telling it to stop. Since hClose on
the same handle will block until the hGetBuf is done, the only way to
stop reading from the handle is to throw an asynchronous exception at
the hGetBuf thread.
Worse, since there is no threadWaitReadHandle :: Handle -> IO (),
there's no way to guarantee that hGetBuf will not be interrupted in
the middle of receiving a packet. From an application perspective,
this invalidates subsequent retrievals unless the protocol is
More information about the Haskell-Cafe