Rules for use of unsafeThaw...

Simon Marlow simonmar at
Fri Nov 4 04:49:47 EST 2005

On 03 November 2005 17:08, Jan-Willem Maessen wrote:

> I've recently been experimenting with unsafeFreeze/unsafeThaw in
> GHC.  Judicious use of these functions vastly reduces GC overhead in
> Data.HashTable.  However, a slightly mis-timed GC will cause the
> whole mess to crash.  I am attempting to understand the invariants
> required to safely use unsafeFreeze/unsafeThaw.
> I believe the following usage ought to be 100% safe:
> 1) Take the last and only reference to a mutable array, and call
> unsafeFreeze to obtain an immutable array.
> 2) Take the last and only reference to an immutable array, and call
> unsafeThaw to obtain a mutable array.

I would like it to be the case that no usage of unsafe{Freeze,Thaw} can
crash the GC.  That perhaps isn't true right now, but I'd like to
understand why not.  

Multiple unsafeThaws on the same array might cause problems in 6.4.1
(but not the HEAD), due to the way the old generation mutable list
works.  That's fixable, if it is the problem.  Multiple unsafeFreezes
should be harmless.  Can you give me a test program?


More information about the Glasgow-haskell-users mailing list