Signals + minimal proposal (was Re: asynchronous exceptions)

Simon Marlow simonmar at
Tue Apr 11 03:54:32 EDT 2006

On 10 April 2006 22:19, John Meacham wrote:
> On Fri, Apr 07, 2006 at 02:58:01PM +0100, Simon Marlow wrote:
>> According to your definition of exitWith above, I can't both raise an
>> exception *and* exit in the same thread.  If I register an onExit
>> handler that throws an exception to the current thread, things go
>> wrong if the current thread also calls exitWith.  Also, you couldn't
>> call exitWith while holding an MVar, if the handlers need access to
>> the same MVar.
> hrm? nothing goes wrong. it is the same as calling 'throw' in the
> current thread.

Your code for exitWith:

exitWith status = do
        takeMVar exitMVar -- winner takes all
        let handleLoop = do
                hs <- swapMVar handlerMVar []
                sequence_ hs
                if null hs then return () else handleLoop
        exitWith_ status

now If I have a handler registered that throws an exception to the
current thread, what happens?  handleLoop is aborted, the exception is
propagated to the top level of the thread, where the top-level exception
handler calls exitWith again, and promptly deadlocks because exitMVar is
already empty.

In the interests of keeping the discussion manageable, I'll deal with
the rest of the points later.


More information about the Haskell-prime mailing list