Optimizations for mutable structures?

John Meacham john at repetae.net
Wed Dec 7 18:33:10 EST 2005

On Wed, Dec 07, 2005 at 05:05:58PM -0000, Simon Marlow wrote:
> No, that is exactly what I disagree with.  Faced with non-derministic
> semantics, the compiler does *not* have to preserve all possible
> outcomes.  In other words, it does not have to assume that an IORef can
> be modified between any two arbitrary instructions.  If we had to assume
> this, then indeed all bets would be off, and C compilers would be very
> much more restricted in what optimisations they could perform.  

Yup. this is exactly why C has the 'volatile' keyword. variables that
are declared volatile will always be read and written to memory and
never stored in a register because they could be modified by external
interrupts or threads. If every varibale were considered volatile
everything would be a whole whole lot slower. I have only had need to
use it 3 times and all were in an operating system kernel.

In any case, ghc IORefs are not 'volatile' in the C sense and that is a
good thing.

John Meacham - ⑆repetae.net⑆john⑈ 

More information about the Glasgow-haskell-users mailing list