Opened 11 years ago

Closed 10 years ago

Last modified 9 years ago

#767 closed bug (fixed)

withMVar family have a bug

Reported by: simonmar Owned by:
Priority: high Milestone: 6.8.1
Component: Compiler Version: 6.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: N/A
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


withMVar is defined like this:

withMVar :: MVar a -> (a -> IO b) -> IO b
withMVar m io = 
  block $ do
    a <- takeMVar m
    b <- catch (unblock (io a))
      	    (\e -> do putMVar m a; throw e)
    putMVar m a
    return b

unfortunately this has a (very rare) bug: catch can raise a stack overflow exception, which would leave the MVar empty.

This is a tricky one. Perhaps in the event of a stack overflow, catch should ensure that the exception is passed directly to its handler, and we always add some extra stack space for the handler.

Change History (6)

comment:1 Changed 11 years ago by igloo

Milestone: 6.8
Test Case: N/A

comment:2 Changed 10 years ago by igloo

Priority: normalhigh

comment:3 Changed 10 years ago by simonmar

Resolution: fixed
Status: newclosed


Fri May 18 13:25:05 BST 2007  Simon Marlow <>
  * FIX #767 (withMVar family have a bug)

comment:4 Changed 10 years ago by igloo

Milestone: 6.8 branch6.8.1

comment:5 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:6 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.