RE: Proposed change to ForeignPtr
Simon Marlow wrote
George: the problem with allowing callbacks from a finalizer is that in order to implement this your system essentially has to be able to make a pre-emptive context switch from the currently running Haskell computation to the finalizer; this turned out to have a fairly high implementation cost for nhc98 and Hugs, so we decided to amend the spec instead. You'll still be able to do this in GHC, of course, but it won't be portable.
However in the case I cited it isn't particularly important to execute the callback at once. If calling Haskell at arbitrary times is unimplementable, could there instead be some way of some way like "wrapper" of exporting a Haskell function [args] -> IO () so that the resulting C function, when executed, merely registers the Haskell action to be executed as soon as the Haskell RTS finds it convenient, rather than at once?
Alastair Reid wrote [snip]
We should provide a C function hs_freeStablePtr and explicitly say that it is safe to call this from inside a finalizer. [snip] This would be the simplest solution, but would not permit you to do anything more sophisticated at the Haskell side, such as reference counting or more complicated strategies to check for possible cycles. You might end up having to do all your inter-language GC code in C, ugh.
George Russell <ger@tzi.de> writes:
However in the case I cited it isn't particularly important to execute the callback at once. If calling Haskell at arbitrary times is unimplementable, could there instead be some way of some way like "wrapper" of exporting a Haskell function[args] -> IO () so that the resulting C function, when executed, merely registers the Haskell action to be executed as soon as the Haskell RTS finds it convenient, rather than at once?
This was the originally proposed solution for re-entrant finalisers in nhc98 and Hugs. The problem is that, certainly for nhc98, it is nigh impossible for the RTS to identify a "convenient" later moment at which to run the delayed finaliser. Regards, Malcolm
participants (2)
-
George Russell -
Malcolm Wallace