[Haskell-cafe] STM and unsafePerformIO/bracket

Brandon Allbery allbery.b at gmail.com
Mon Feb 3 15:15:56 UTC 2014

On Mon, Feb 3, 2014 at 5:50 AM, Rob Leslie <rob at mars.org> wrote:

> I’ve run into a difficulty I’d appreciate some advice to solve.
> I am trying to make a call to C (through the FFI) within an STM
> transaction to compute what is effectively a pure result. By itself this
> doesn’t seem to be a problem, except that the C function depends on some
> global state in a way that compromises thread safety, and so I would like
> to

This does not sound particularly pure to me, from a Haskell standpoint.

>  unsafePerformIO $ bracket (takeMVar lock) (putMVar lock) $ \_ -> do

And this looks to me like completely undefined behavior. I suspect bracket
*can't* work in unsafePerformIO.

brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140203/71f404db/attachment.html>

More information about the Haskell-Cafe mailing list