[threads] Keep the tid after the thread has finished (#5615)