[Haskell-cafe] Printing of asynchronous exceptions to stderr

Mitar mmitar at gmail.com
Fri Dec 17 00:03:04 CET 2010


On Thu, Dec 16, 2010 at 10:30 AM, Simon Marlow <marlowsd at gmail.com> wrote:
> I've thought about whether we could support resumption in the past. It's
> extremely difficult to implement - imagine if the thread was in the middle
> of an I/O operation - should the entire I/O operation be restarted from the
> beginning?

Yes, this is the same problem as when designing an operating system:
what should happen to a system call if it is interrupted. And I agree
with elegance of simply returning EINTR errno. This makes system calls
much easier to implement and for user it is really simple to wrap it
in a loop retrying it. So it is quite often to see such function:

static int xioctl( int fd, int request, void *arg) {
 int r;

 do {
   r = ioctl(fd, request, arg);
 } while (-1 == r && EINTR == errno);

 return r;

And this is why, once I recognized similarities decided to use my
uninterruptible function. So as resumption is hard to do then such
approach is a valid alternative.

I agree with you, that the best would be that there would be no need
for such functions as you would make sure that exceptions are raised
only in threads you want. But this is hard to really satisfy when
using complex programs with many threads and many exception throwing
between them and especially if you are using third-party libraries you
do not know much about and which could throw some exception to some
other thread you haven't expected. This is why it is good to make sure
that things will work as expected even if some exception leaks in. It
would be great if type system would help you here: maybe a separate
(type) system just for exception coverage checking which would build a
graph from code of how all could exceptions be thrown (this would
require following of how ThreadId values are passed around, as
capability tokens for throwing an exception) and inform/warn you about
which exceptions can be thrown in which code segments. And you could
specify which exceptions you predict/allow and if there would be a
mismatch you would get an compile-time error.


More information about the Glasgow-haskell-users mailing list