This function adds a finalizer to the given ForeignPtr. The finalizer will run before all other finalizers for the same object which have already been registered.
This is a variant of addForeignPtrFinalizer, where the finalizer is an arbitrary IO action. When it is invoked, the finalizer will run in a new thread.
NB. Be very careful with these finalizers. One common trap is that
if a finalizer references another finalized value, it does not
prevent that value from being finalized. In particular, System.IO.Handles
are finalized objects, so a finalizer should not refer to a
System.IO.Handle (including GHC.Internal.System.IO.stdout, GHC.Internal.System.IO.stdin, or
GHC.Internal.System.IO.stderr).