Optimizations for mutable structures?
igloo at earth.li
Wed Dec 7 10:13:34 EST 2005
On Wed, Dec 07, 2005 at 02:15:24PM -0000, Simon Marlow wrote:
> On 07 December 2005 13:38, Malcolm Wallace wrote:
> > Jan-Willem Maessen <jmaessen at alum.mit.edu> writes:
> >> - Fetch elimination for imperative reads:
> >> writeIORef r e >> acts >> readIORef r
> >> === writeIORef r e >> acts >> return e
> > This transformation is valid only on single-threaded systems.
> > If there is any possibility of an IORef being shared across threads,
> > you are out of luck.
> (assuming 'acts' doesn't modify 'r').
> No, Jan's transformation is correct even in a multithreaded setting. It
> might eliminate some possible outcomes from a non-deterministic program,
> but that's ok. There's no requirement that all interleavings according
> to the semantics have to be implemented. This is a hard property to
> state precisely, indeed we gave up trying to in the concurrency/FFI
> paper: http://www.haskell.org/~simonmar/papers/conc-ffi.pdf, see Section
I don't think it's true for this program:
main = do m1 <- newEmptyMVar
m2 <- newEmptyMVar
let e = 6
not_e = 7
acts = putMVar m1 () >> takeMVar m2
r <- newIORef 5
forkIO $ do takeMVar m1
writeIORef r not_e
putMVar m2 ()
writeIORef r e
readIORef r >>= print
More information about the Glasgow-haskell-users