
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. Are there any other usage modes which are GC-safe? In particular, is it possible for a reference to the frozen array to exist somewhere on the heap when a call to unsafeThaw occurs? Is there a particular set of circumstances under which we might get away with this (eg, no allocation during the interval where the ambiguous references occur)? -Jan-Willem Maessen

Hello Jan-Willem, Thursday, November 03, 2005, 8:08:09 PM, you wrote: JWM> I've recently been experimenting with unsafeFreeze/unsafeThaw in JWM> GHC. Judicious use of these functions vastly reduces GC overhead in JWM> Data.HashTable. However, a slightly mis-timed GC will cause the JWM> whole mess to crash. i had (for another reason) proposal for adding disableGC/enableGC primitives to GHC. Simon Marlow says that it is in principle possible, although is not easy -- Best regards, Bulat mailto:bulatz@HotPOP.com

On Nov 3, 2005, at 12:16 PM, Bulat Ziganshin wrote:
Hello Jan-Willem,
Thursday, November 03, 2005, 8:08:09 PM, you wrote:
JWM> I've recently been experimenting with unsafeFreeze/unsafeThaw in JWM> GHC. Judicious use of these functions vastly reduces GC overhead in JWM> Data.HashTable. However, a slightly mis-timed GC will cause the JWM> whole mess to crash.
i had (for another reason) proposal for adding disableGC/enableGC primitives to GHC. Simon Marlow says that it is in principle possible, although is not easy
I'd rather the performance problems with tracing of large mutable objects were fixed, frankly. And I rather suspect I can Do The Right thing here without enabling/disabling GC (by swapping out refs and swapping them back in again, if need be). But there are definitely times this'd be interesting. -Jan
-- Best regards, Bulat mailto:bulatz@HotPOP.com
participants (2)
-
Bulat Ziganshin
-
Jan-Willem Maessen