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 validStgStablePtr(it is an index into an array (stable_ptr_table)) (set to NULL ininitTopHandler), so we easily hit thebarfcase ingetTopHandlerThread(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?