[threads] Assert that every thread is detached when exiting (#3620)