Optimizations for mutable structures?
simonmar at microsoft.com
Thu Dec 8 05:24:26 EST 2005
On 08 December 2005 09:40, Simon Marlow wrote:
> If you share IORefs between threads and run on a multiprocessor, you
> are at the mercy of both sequential optimisations and your
> architecture's memory consistency guarantees. In other words, don't
> do it. Use communication primitives that have strong properties in a
> multi-threaded setting.
I realised this paragraph is a bit stronger than I meant. Of course
it's fine to share IORefs between threads as long as you use a proper
communication primitive to synchronise access to the IORef. eg. using
one MVar to lock on a bunch of IORefs is perfectly fine (this is how
GHC's IO library is implemented).
More information about the Glasgow-haskell-users