[runtime] Thread teardown race condition.  Fixes #13813.