[runtime] Fix an assertion which is hit if thread_cleanup () is called for a thread after it has been finalized during shutdown.