asynchronous exceptions (was: RE: Concurrency)

John Meacham john at
Wed Apr 5 08:38:26 EDT 2006

On Wed, Apr 05, 2006 at 07:47:08AM -0400, David Roundy wrote:
> For me, asynchronous exceptions are the primary reason to use concurrent
> Haskell.  They're the only way I'm aware of to write a program that handles
> signals in Haskell, and it's be a real shame to leave Haskell' programs
> unable to handle signals--it means that any real-world programs that deal
> with locking or the like will need to use non-standard extensions.  Unless
> you can come up with some other way to deal with signals.  Having no chance
> to clean up when control-C is hit isn't an acceptable alternative, and
> neither is simply ignoring control-C and forcing users to run kill (and
> then once again get no chance to clean up!).

I have been giving signals some thought, and resarching what other
languages do, and have a semi-proposal-maybe.

signals tend to be used for one of a couple purposes (some can fall into
multiple categories):

signal a synchronous exceptional event - SIGFPE, SIGPIPE, SIGILL, SIGSEGV
signal an asynchronous exceptional event - SIGINT, SIGHUP (interactive)
inform the app of an event it might want to take note of -  SIGALRM, SIGCHLD, SIGWINCH, SIGHUP (daemon)

I think it would make sense to have 3 mechanisms to cover these cases.

signal a synchronous exceptional event
- raise a (possibly imprecise) exception on the thread that produced the signal.

signal an asynchronous exceptional event
- the user should be able to choose the threads on which they wish to
  catch these, those that need to clean up after themselves. 

inform the app of an event it might want to take note of
- these should run on their own thread, concurrently to all other

data Signal = ...
data SigInfo = SigInfo { ... }

-- | declare which signals should throw a synchronous exception always
(because they are thread specific)

signalException :: [Signal] -> IO ()
signalExceution = ...

-- | declare that a thread should catch the given asynchronous signals during the
processing of the argument

signalCatch :: 
        [Signal] -- ^ the signals I care about
        -> IO a  -- ^ while running this, signals will be delivered as
                        an exception to this one. (not necessarily
        -> IO a

signalCatch = ...

-- | declare a signal should perform a task in its own thread,
exceptions thrown will be discarded.

signalAction :: [Signal] -> (SigInfo -> IO ()) -> IO ()
signalAction = ...

these roughly corespond to the Core,Term,and Ign type signals

ideally, we should specify some default behaior, 

ILL,FPE,SEGV raise synchronous exceptions
SIGPIPE ignored


John Meacham - ⑆⑆john⑈

More information about the Haskell-prime mailing list