Callback destruction after RTS shutdown
As issue #33 (closed) points out, if a callback is saved into a C++ variable that persists past the lifetime of the GHC RTS, then it's too late to be calling back into Haskell to do freeHaskellFunPtr
, and we get the following warning as the program shuts down:
hoppy-example: newBoundTask: RTS is not initialised; call hs_init() first
If we can check whether the RTS is alive from a callback's destructor, then we could do nothing if it's dead. Or perhaps we can use hs_free_fun_ptr()
. One problem with both of these is that if the RTS is shut down and started up again as is explicitly allowed by hs_exit()
/hs_init()
, then our function pointers will be garbage, so it might be better to see whether we can use finalizers or some RTS shutdown hook to invalidate callbacks.