Merge "Avoid debug check violation in thread registration."