[Haskell-cafe] Brackets and Asynchronous Exceptions

Andrew Gallagher ajcg at CS.UCLA.EDU
Wed Apr 15 19:06:45 EDT 2009


In a program I am writing, I have many locations where I acquire a 
resource, perform an operation with it, then release it.  I have been 
the 'bracket' function so that the "release" operation would be performed 
even if the operation threw an exception.  This seems to work nicely.

In the event of an asynchronous exception, however, is there a possible 
scenario where a release is not performed after an acquire?

Looking at the example given in bracket documentation:

    (openFile "filename" ReadMode)
    (\fileHandle -> do { ... })

Is it possbile that an asynchronous exception could be raised in this 
thread after openFile executes but *before* the appropriate handlers are 
installed and the operation is run, preventing hClose from executing?

If 'bracket' does not handle this case, should I be using the 
block/unblock functions to disable asynchronous exceptions:

       (openFile "filename" ReadMode)
       (\fileHandle -> do
          ({ ... })))


More information about the Haskell-Cafe mailing list