Indeed, I very nearly implemented such a thing as part of the patch I sent out. However, it didn't look trivial enough to implement so I backed off. The "blocked" state needs to be saved & restored at various points: when starting a finalizer, when invoking a foreign-exported function, and when invoking an exception handler.
I think it's fairly easy. A sketch is something like:
// primitive called from Haskell void blockFinalizer(Cell m, State world) { blocked += 1; eval(ap(m,world)); blocked -= 1; runFinalizers(); }
Does this run into problems with exceptions? Also, this is a nested call to eval(), in a primitive, which can invoke an IO action and therefore re-enter Haskell without going through unsafePerformIO. Is that safe? Cheers, Simon