[runtime] Fix an assert if a thread cannot be created. Fixes #18000.