Skip to content

getTopHandlerThread questions/issues

The concept of the top handler thread was introduced in 12ad4d41 to allow for throwing heap overflow exceptions to the "main" thread (#1791 (closed)).

I think there are some possible issues with the implementation:

  • For a program where haskell is not the "host" the main haskell thread is not well defined
  • NULL (0) is a valid StgStablePtr (it is an index into an array (stable_ptr_table)) (set to NULL in initTopHandler), so we easily hit the barf case in getTopHandlerThread (ie the first slot in the stable pointer table is filled with something that isn't a weak reference to the main thread).

It seems like it would be reasonable to opt out of heap overflow exceptions by having getTopHandlerThread behave well if the rts_setMainThread is never called. Perhaps a flag to indicate if topHandlerPtr was properly initialised?

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information